我有这种情况
@XmlType(name ="", propOrder={"value"})
@XmlRootElement(name = "compound")
public class Compound extends Value {
@XmlElements({
@XmlElement(name="simple", type=Simple.class),
@XmlElement(name="compound", type=Compound.class)
})
protected List<Value> value;
// ...
}
因此,复合是简单和/或复合的列表。两者都从定义为的值扩展
public abstract class Value implements Serializable {}
Simple 是一个标有适配器的类,用于编组/解组到/从简单字符串
@XmlJavaTypeAdapter(SimpleAdapter.class)
public class Simple extends Value {
private java.lang.String simple;
// ...
}
Compound 不需要适配器。
问题是,如果我使用简单的“原样”,它会正确地编组/解组为
<simple>my.text.here</simple>
但是如果我在 Compound 中使用它,它会输出类似
<compound>
//...
<simple>
<value>my.text.here</value>
</simple>
//...
</compound>
我只是想知道为什么...我错过了什么吗?我怎样才能删除那个“价值”?在我看来,适配器根本没有使用,是否可以在 @XmlElements 内标记的类型中使用适配器?
编辑
经过几次测试,我发现问题可能出在我如何处理简单实例上。因此,我将最初的问题简化为:
给定一个简单的类
@XmlRootElement("simple")
public class Simple {
private java.lang.String innerText;
// getters/setters
}
我怎样才能获得像这样的编组输出
<simple>
my.inner.text.here
</simple>
代替
<simple>
<value>my.inner.text.here</value>
</simple>
?