Use Jackson JSON library with JAXB annotations

I'm trying to enable JAXB annotation support in my RESTEasy-based web application, and this article suggested to me (http://wiki.fasterxml.com/JacksonJAXBAnnotations). I can get jackson-xc.jar, but I don't see how to register the annotation introspector. RESTEasy is currently automatically serializing my JSON responses, where will it fit below? RESTeasy is currently automatically serializing a JSON object.

Include json json json that contains org.codehaus.jackson.xc.JaxbAnnotationIntrospector Register this annotation introspector

    ObjectMapper mapper = new ObjectMapper();
    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
    // make deserializer use JAXB annotations (only)
    mapper.getDeserializationConfig().setAnnotationIntrospector(introspector);
    // make serializer use JAXB annotations (only)
    mapper.getSerializationConfig().setAnnotationIntrospector(introspector);
+3
source share
2 answers

, RESTeasy ObjectMapper, . JAX-RS , RESTeasy. JAX-RS JAXB .

: , JAXB? , , Jackson . JAXB , xml-, JSON .

+2

, ...

, jaxb, , @XmlRootElement (name= "UserResponse" ) JSON. . :

{ "response": { " userResponse": [{ "user": { "businessRegion": "US", "firstName": "joe", "language": "en", "lastName": "smith" }}}]} , , { "response": [{ "user": { "businessRegion": "US", "firstName": "joe", "": "", "LastName": "" }}]}. @XmlRootElement Jackson -?

: @XmlAccessorType (XmlAccessType.FIELD) @XmlRootElement (name= "userResponse" ) public class UserResponse extends AbstractResponse {    ;

+1
source

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


All Articles