From a common JAXB model the xml generated can be of the form
<ipi-list><ipi>1001</ipi><ipi>1002</ipi></ipi-list>
because in json we have arrays we dont need both elements, so by using MOXy's oxml extensions I can flatten the output to give
"ipi" : [ "1001", "1002" ],
but because ipi now refers to an array of things I would like it to be called ipis not ipi
"ipis" : [ "1001", "1002" ],
Is there a way to get MOXy to rename an element ?
You could use EclipseLink JAXB (MOXy)'s external mapping document to tweak the mapping for either the XML or JSON representation.
IPIList
Below is a domain class with JAXB annotations that matches the XML representation from your question:
oxm.xml
We can use MOXy's external mapping document to modify how the
list
property is mapped to JSON.jaxb.properties
To specify MOXy as your JAXB provider you need to include a file called
jaxb.properties
in the same package as your domain model with the following entry (see ):Demo
The following demo code shows how to reference the external mapping document when creating a
JAXBContext
.Output
Here is the output from running the demo code:
For More Information