5

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:

  1. The root node to be named car.
  2. I want Car to be lowercase in the xml:

For example:

<car><engine-type>v8</engine-type></car>

Thanks

Ernest Sadykov
  • 831
  • 8
  • 28

1 Answers1

12

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 {
}
Community
  • 1
  • 1
Thánh Ma
  • 133
  • 1
  • 8