I have a requirement to marshal both json and xml outputs. But, how to generate JSON output using MOXy JAXB in Spring? I can generate the xml file as shown in the example at: http://wiki.eclipse.org/EclipseLink/Examples/MOXy/Spring/JAXBDynamicOXM
The documentation does not have any examples for outputting json. I know that I can use JAXB Marshaller to generate the json output by setting the jaxb properties. How to do the same using MOXy/Spring/JAXB?
Appreciate your help!
Note: I’m the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.
The following answer is based on the example from the MOXy wiki:
eclipselink-oxm.xml
Normally JAXB/MOXy is used with a static domain model. In the example you lined to there there isn’t a real model, all the metadata is supplied via MOXy’s metadata file.
jaxb.properties
To use MOXy with dynamic models you need to specify a different jaxb.properties file than normal:
Demo
In the example below we will convert an XML document into a dynamic model, and then marshal it to JSON. Note the context path (“forum12162216” in this example) must correspond to the package name that contains the jaxb.properties file. JSON binding is enabled by setting the
"eclipselink.media-type"property on theMarshaller.customer.xml
Output
For More Information