开发者

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.Accessible开发者_运维百科Object.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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜