Hey. I need to create XML from JAVA using XMLMapper using Jackson-dataformat. XML should look like
<Customer> <id>1</id> <name>Mighty Pulpo</name> <addresses> <city>austin</city> <state>TX</state> </addresses> <addresses> <city>Hong Kong</city> <state>Hong Kong</state> </addresses> </Customer>
But I always get it with the optional tag "<addresses> </addresses>".
<Customer> <id>1</id> <name>Mighty Pulpo</name> <addresses> <addresses> <city>austin</city> <state>TX</state> </addresses> <addresses> <city>Hong Kong</city> <state>Hong Kong</state> </addresses> <addresses> </Customer>
I use below code to create XML
JaxbAnnotationModule jaxbAnnotationModule = new JaxbAnnotationModule(); XmlMapper mapper = new XmlMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.registerModule(jaxbAnnotationModule); mapper.registerModule(new GuavaModule()); String xml = mapper.writeValueAsString(customer); System.out.println(xml);
Please help me? How can I remove the extra tag, please. I tried using @XmlElement, but that will not help. TIA !!
java xml jackson pojo
Sharmistha sinha
source share