你明智地得到结构:
<someTypes class="list-type">
<someType>
....
</someType>
...
</someTypes>
看下面的代码。对于您的列表,您需要标记:
@XStreamImplicit(itemFieldName="someType")
List<someType>List;
现在,根据你里面的内容,你可能需要创建一个自定义转换器。要引用它,您可以进行如下更改:
@XStreamImplicit(itemFieldName="someType") @XStreamConverter(YourOwnConverter.class)
List<SomeType> someTypeList;
然后创建一个YourOwnConverter
知道如何取消/编组的转换器类 ( ):
public boolean canConvert(Class type)
{
return type.equals(SomeType.class);
}
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context)
{
SomeType mytype = (SomeType) source;
writer.addAttribute("position", mytype.getPosition());
writer.setValue(mytype.getId());
}
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context)
{
SomeType mytype = new SomeType();
String position = reader.getAttribute("position");
......
return mytype ;
}
以此为例:http:
//x-stream.github.io/converter-tutorial.html