我使用XStream将我的java对象输出到XML。 Java类是从WSDL生成的客户端类。我得到的输出就像:
<ROOT_TAG>
<sections>
<com.tarun.local.xstream.test.Sections>
<position>1</position>
<rank>1</rank>
<scores>
<com.tarun.local.xstream.test.Scores>
<number>100</number>
</com.tarun.local.xstream.test.Scores>
</scores>
</com.tarun.local.xstream.test.Sections>
</section>
</ROOT_TAG>
如何删除打印的额外包装标签? 输出应该是:
<ROOT_TAG>
<sections>
<position>1</position>
<rank>1</rank>
<scores>
<number>100</number>
</scores>
</section>
</ROOT_TAG>
答案 0 :(得分:0)
您需要应用别名,via code或annotations:
@XStreamAlias("section")
@XStreamImplicit(itemFieldName="part")
答案 1 :(得分:0)
我想你想省略那个字段,所以答案是:
XStream x = new XStream();
x.omitField(A.class, "com.tarun.local.xstream.test.Sections");
x.omitField(A.class, "com.tarun.local.xstream.test.Scores");