我有一些 jaxb 对象使用具有值的容器对象建模元数据结构,这可能是另一个容器对象或只是一个简单的对象(例如字符串)。
@XmlRootElement(name = "value")
public class Value
{
protected SimpleType type;
protected Container container;
@XmlElement
public SimpleType getType()
{
return type;
}
public void setType(SimpleType type)
{
this.type = type;
}
@XmlInverseReference(mappedBy="value")
@XmlElement
public Container getContainer()
{
return container;
}
public void setContainer(Container container)
{
this.container = container;
}
}
@XmlRootElement(name = "container")
public class Container
{
protected Value value;
@XmlElement
public Value getValue()
{
return value;
}
public void setValue(Value value)
{
this.value = value;
}
}
@XmlRootElement(name = "type")
@XmlEnum
public enum SimpleType
{
@XmlEnumValue("String")STRING,
@XmlEnumValue("Boolean")BOOLEAN,
....etc.
}
XML 看起来不错,但 JSON 最终具有重复的“容器”属性。
<container>
<value>
<container>
<value>
<type>String</type>
</value>
</container>
</value>
</container>
"container": {
"value": {
"container": {
"container": {
"value": {
"type": "STRING"
}
}
}
}
}
知道为什么会有这种差异吗?