In my application the JAXB output generates like:
this.marshalOut(jaxb_Object, fileOutputStream);
this is method call to the spring Object XML Mapping Marshallers that generate XML files. Now, I also like to generate JSON files after this line. Any one have idea about generating JSON output using JAXB input.
I found this example code online:
ObjectMapper mapper = new ObjectMapper();
AnnotationIntrospector introspector = new JacksonAnnotationIntrospector();
// make deserializer use JAXB annotations (only)
mapper.getDeserializationConfig().setAnnotationIntrospector(introspector);
// make serializer use JAXB annotations (only)
mapper.getSerializationConfig().setAnnotationIntrospector(introspector);
mapper.writeValue( outputStream, jaxb_object);
The setAnnotationIntrospector
is deprecated, is there any other way of solving this problem?
The following works (and does not use any deprecated constructors) :
ObjectMapper mapper = new ObjectMapper();
AnnotationIntrospector introspector =
new JaxbAnnotationIntrospector(mapper.getTypeFactory());
mapper.setAnnotationIntrospector(introspector);
Specifically, this line
new JaxbAnnotationIntrospector(mapper.getTypeFactory());
uses a non-deprecated constructor. I've tested this and it successfully processes JAXB Annotations (such as @XmlTransient, in my case).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With