Use Jackson JSON processor without using annotations

后端 未结 2 1702
别那么骄傲
别那么骄傲 2021-01-17 05:05

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 X

相关标签:
2条回答
  • 2021-01-17 05:32

    My current investigations lead to these results:

    The usage of the DeserializationConfig.Feature.USE_ANNOTATIONS property (set to false) will cause the JACKSON DeserializerConfig class to use a NopAnnotationIntrospector. Annotations of a class will then be resolved using this NopAnnotationIntrospector. The NopAnnotationIntrospector will return false on each isHandled request 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 = false would 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.

    0 讨论(0)
  • 2021-01-17 05:52

    For what it's worth, Jackson trunk (pre-1.8.0) has code changes that will try to fully disable annotation processing; and theoretically this should solve the issue. One unfortunate thing is that this problem does NOT occur on regular J2SE JVM, but only on Android; so fix needs to be verified on Android. So it would be good to have an Android developer verify whether fix fully address the issue (if not, more work is needed).

    0 讨论(0)
提交回复
热议问题