Affects Version/s: 1.3.1
Fix Version/s: 1.4
JDK version and platform:Android 1.1
When using XStream for deserialization with Android 1.1, and using annotations (both autodetectAnnotations(true) and processAnnotations()), I get:
com.thoughtworks.xstream.XStream$InitializationException: No com.thoughtworks.xstream.mapper.AnnotationMapper available
When using explicit non-annotated aliases etc. the deserialization works perfectly. Would it be that Dalvik somehow filters out the AnnotationMapper.class from the jar??
I ran into this issue as well and I'm wondering if there is some progress on a fix.
I'm currently developing a Android 1.6 application, which is still reporting 0.9 in the "java.specification.version" property. If I set the property to 1.5 a new exception appears when calling the XStream constructor:
Caused by: java.lang.NullPointerException
1.4-SNAPSHOT works on Android (2.1), kind of. If you set java.specification.version to 1.5 then the issue is that the automatically registered DurationConverter isn't available - Dalvik doesn't include the jaxp impl classes. However, if you set it to 1.4, then the AnnotationMapper isn't available to Xstream (but Dalvik can do annotations). As a workaround I do:
HierarchicalStreamDriver driver = new XppDriver();
XStream xstream = new XStream(driver);
JVM jvm = new JVM();
AnnotationMapper annotationMapper = new AnnotationMapper(xstream.getMapper(), (ConverterRegistry) xstream.getConverterLookup(), xstream.getClassLoader(), xstream.getReflectionProvider(), jvm);
xstream = new XStream(xstream.getReflectionProvider(), driver, xstream.getClassLoader(), annotationMapper);
It would be nicer if there was a simpler way to add mappers or if you could disable registering some converters explicitly.
Android behaves now like a Java 5 version in pure mode. If registration of the DurationConverter fails, it will be ignored. It seems that current Android version support Duration now. Fixed in HEAD.
XStream is compatible down to JDK 1.3. Therefore annotation support is added dynamically when running on a JDK that implements java.specification.version 1.5. At least Android 1.0 returned here only 0.9. I have no idea for Android 1.1. Can you run com.thoughtworks.xstream.core.JVM.main() and report the output of the console? For further testing you may also try to set this system property to 1.5 and run your application and tell whether it works then.