FrVaBe
FrVaBe

Reputation: 49341

Stop Gson from introspecting class annotations

I try to use Gson on Android to marshall/unmarshall JAXB annotated classes.

The JAXB (XML) annotations are not provided on the Android device, thus the JSON library MUST not inspect annotations - otherwise we run into java.lang.NoClassDefFoundError: javax.xml.bind.annotation.XmlElement.

I have the same problem using Jackson but that seems to be fixed (thanks to StaxMan). As I do not know when the fix will be released I thought Gson would be an alternative, because of this documentation statement:

There is no need to use any annotations to indicate a field is to be included 
for serialization and deserialization. All fields in the current class (and 
from all super classes) are included by default.

Unfortunately I nevertheless run into this problem:

ERROR/AndroidRuntime(338): java.lang.NoClassDefFoundError: javax.xml.bind.annotation.XmlElement
ERROR/AndroidRuntime(338):     at java.lang.reflect.Field.getDeclaredAnnotations(Native Method)
ERROR/AndroidRuntime(338):     at java.lang.reflect.Field.getDeclaredAnnotations(Field.java:196)
ERROR/AndroidRuntime(338):     at java.lang.reflect.AccessibleObject.getAnnotations(AccessibleObject.java:199)
ERROR/AndroidRuntime(338):     at com.google.gson.FieldAttributes.getAnnotations(FieldAttributes.java:159)

Is there a way to turn of Annotation inspection in Gson?

Thanks Klaus

Upvotes: 3

Views: 1056

Answers (1)

Tim Sparg
Tim Sparg

Reputation: 3304

xStream has some JSON support built in, maybe you should try that and see what the result is.

Upvotes: 1

Related Questions