简体   繁体   中英

How to change the xml class name using fasterxml jackson?

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

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 {
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM