我使用SimpleFramework来创建XML。一切都很好,除了一件"小"事。当我的一个列表为空时,SimpleFramework继续添加列表的标记(当然是空的)。我怎么能告诉Simpleframework不添加空标签时,它是null或有大小== 0 ?
XML类:
@Root(name="title")
public class XML {
@ElementList(name="tags", inline=true, required=false, empty=true)
@Path("tags")
private List<Tag> tags;
}
标签类别:
@Root(name="tag")
public class Tag {
@Text
private String name;
}
当列表为空时:
生成输出:
<xml>
<tags/>
<otherTag>1</otherTag>
<otherTag>2</otherTag>
</xml>
预期输出:<xml>
<otherTag>1</otherTag>
<otherTag>2</otherTag>
</xml>
删除Path
对tags
属性的注释并尝试:
@ElementList(name="tags", inline=true, required=false, empty=true)
//@Path("tags")
private List<Tag> tags;