Jackson XML 手册这样写对象
<Simple>
<x>1</x>
<y>2</y>
</Simple>
在 https://github.com/FasterXML/jackson-dataformat-xml 但在我的代码中,它有 [xmlns=""],而且它不属于我的业务。
我的代码:
public class Sample {
private int id=1;
private String name="abc";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public static void main(String[] args) throws Exception {
XmlMapper mapper = new XmlMapper();
System.out.println(mapper.writeValueAsString(new Sample()));
//<Sample xmlns=""><id>1</id><name>abc</name></Sample>
}
}
最佳答案
如上一篇文章 issue 32 中所述:
Using Stax implementation other than one that is bundled with JDK: both Woodstox and Aalto work in a way that does not produce this extra (harmless) namespace declaration.
关于java - 将对象序列化为 XML,无需 [xmlns =""],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27372898/