简体   繁体   English

如何使用fasterxml jackson更改xml类名?

[英]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. 我试图弄清楚如何使用jackson fastxml更改根节点名称。

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. 要命名为car的根节点。
  2. I want Car to be lowercase in the xml: 我希望Car在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: 我想您可以在这里找到您的解决方案: 如何使用FasterXML使用注释反序列化XML为什么不使用@JacksonXmlRootElement像这样:

@JacksonXmlRootElement(localName = "car")
public class Ford extends Car {
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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