Stop Gsson from annotating to class introspection

I am trying to use Gson on Android to sort / undo JAXB annotated classes.

JAXB annotations (XML) are not presented on the Android device, so the JSON library SHOULD NOT check annotations, otherwise we will run into java.lang.NoClassDefFoundError: javax.xml.bind.annotation.XmlElement.

I have the same problem using Jackson , but it seems to be fixed (thanks StaxMan). Since I do not know when the fix will be released, I thought Gson would be an alternative due to 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 still ran 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 enable annotation checking in Gson?

Thanks Klaus

+3
source share
1 answer

xStream has native JSON support , maybe you should try this and see what the result is.

+1
source

Source: https://habr.com/ru/post/1792566/


All Articles