I am trying to figure out how to change the root node name using jackson fasterxml.
For example:
public class Car {
@JsonProperty("engine-type")
String engineType = "v8";
}
public class Ford extends Car {
}
Ford car = new Ford();
ObjectMapper xmlMapper = new XmlMapper();
System.out.println(xmlMapper.writeValueAsString(this));
results in:
<Ford><engine-type>v8</engine-type></Ford>
This is what I want:
For example:
<car><engine-type>v8</engine-type></car>
Thanks
Jackson is a library for handling JSON in Java systems and now has support for XML from version 2. DOM4J is a memory-efficient library for parsing XML, XPath, and XSLT (eXtensible Stylesheet Language).
Package. Description. com.fasterxml.jackson.dataformat.xml. Package that contains XML-based backends which can serialize POJOs to and deserialize from XML, using Stax XML parsers and generators for XML processing and mostly standard Jackson data binding otherwise.
Reading XML We can also read XML, using the various readValue APIs that are part of provided by the ObjectMapper. For example, reading some XML from an InputStream into a Java Bean: MyBean bean = objectMapper.
I think you could find your solution here: How to deserialize XML with annotations using FasterXML Why don't you use @JacksonXmlRootElement like:
@JacksonXmlRootElement(localName = "car")
public class Ford extends Car {
}
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