I have a package which just includes and xsd file to generate (via JAXB) shared classes which are relevant for our server and client applications. So these classes contain XML annotations.
One client is an Android App. I also want to use these classes here for JSON deserialization because I communicate with a REST service which delivers JSON (with Jersey/Jackson).
I try to use Jackson (version 1.7.2) on the Android like this:
ObjectMapper mapper = new ObjectMapper();
mapper = mapper.configure(DeserializationConfig.Feature.USE_ANNOTATIONS,
false);
mapper = mapper.configure(SerializationConfig.Feature.USE_ANNOTATIONS,
false);
FooBar someObject = (FooBar) mapper.readValue(jsonString, FooBar.class);
I though configure the MAPPER should avoid using annotations but I still get
02-07 09:30:18.631: ERROR/AndroidRuntime(447): java.lang.NoClassDefFoundError: javax.xml.bind.annotation.XmlAccessorType
02-07 09:30:18.631: ERROR/AndroidRuntime(447): at java.lang.Class.getDeclaredAnnotations(Native Method)
02-07 09:30:18.631: ERROR/AndroidRuntime(447): at org.codehaus.jackson.map.introspect.AnnotatedClass.resolveClassAnnotations(AnnotatedClass.java:292)
02-07 09:30:18.631: ERROR/AndroidRuntime(447): at org.codehaus.jackson.map.introspect.AnnotatedClass.construct(AnnotatedClass.java:139)
Who knows the trick to stop Jackson from resolving annotations.
Thanks
Klaus
My current investigations lead to these results:
The usage of the
DeserializationConfig.Feature.USE_ANNOTATIONSproperty (set to false) will cause the JACKSONDeserializerConfigclass to use aNopAnnotationIntrospector. Annotations of a class will then be resolved using thisNopAnnotationIntrospector. TheNopAnnotationIntrospectorwill returnfalseon eachisHandledrequest for any annotation on a class – and in fact will not use this annotation in further processing.So – the system still “inspects” the annotations – which have to be on the Classpath in this case. As Android does not provide any jaxb-api annotations this leads to the
NoClassDefFoundError.I expected
USE_ANNOTATIONS = falsewould bring JACKSON to totally ignore any annotations – but unfortunately it does not. I will now use the Jackson Streaming API to parse the JSON string instead of using JACKSON Data Binding capabilities.