有没有办法通过jackson序列化java var(例如int)作为xml属性?我找不到任何特定的jackson或json注释(@XmlAttribute @ javax.xml.bind.annotation.XmlAttribute)来实现这一点.
例如
public class Point {
private int x, y, z;
public Point(final int x, final int y, final int z) {
this.x = x;
this.y = y;
this.z = z;
}
@javax.xml.bind.annotation.XmlAttribute
public int getX() {
return x;
}
...
}
Run Code Online (Sandbox Code Playgroud)
我想要的是:
<point x="100" y="100" z="100"/>
Run Code Online (Sandbox Code Playgroud)
但我得到的只是:
<point>
<x>100</x>
<y>100</y>
<z>100</z>
</point>
Run Code Online (Sandbox Code Playgroud)
有没有办法获取属性而不是元素?感谢帮助!
我尝试使用XMLMapper将一些配置类序列化为xml配置文件.但是我对属性生成有些麻烦.实际上生成的XML是完美的,但XMLMapper有时会为我的属性名称添加前缀.
例如
<Config zdef-2031720317:value="0">
Run Code Online (Sandbox Code Playgroud)
代替
<Config value="0">
Run Code Online (Sandbox Code Playgroud)
这真的很糟糕,因为我不能再用XOM处理xml结构了:(
这种效果来自哪里?我发现xml生成器似乎会自动修复命名空间以使属性唯一.为什么这是必要的,我该如何避免呢?