@XStreamConverter currently only supports Converters which take none or a small set of arguments using DependencyInjectionFactory (AnnotationMapper, ClassLoader, ReflectionProvider, and/or JVM), but not the target type. It's fairly common that a Converter would want to know what type of value to which it's trying to convert. This is especially true for SingleValueConverters which do not have any way to get this information (full Converters can get it from the UnmarshallingContext, but then can't be used as attributes).
I've included a replacement AnnotationMapper and test case.
The changes to AnnotationMapper are fairly minor:
- Modified the cacheConverter method to take the target Class argument
- Added the target Class to the arguments when calling DependencyInjectionFactory.newInstance(...).
- Modified the internal cache to make sure that it caches both the converterType and the target class with the Converter instance rather than just the converterType with the Converter instance. This makes the caching less efficient, but makes sure that a ToStringConverter instance for Doubles doesn't try to convert a Boolean.
The test class included makes use of the ToStringConverter which is included with the standard distribution.