我有以下XML:
<com.abc.xyz.container>
<data class="list">
<com.xyz.abc.VO.fruits>
<id>28</id>
<name>
<![CDATA[ Apple ]]>
</name>
</<com.xyz.abc.VO.fruits>
<com.xyz.abc.VO.fruits>
<id>29</id>
<name>
<![CDATA[ Orange ]]>
</name>
</<com.xyz.abc.VO.fruits>
<com.abc.xyz.container>
我尝试以这种方式创建课程:
@Root(name = "com.abc.xyz.container")
public class Response {
@Element(required = false)
private Data list;
public Data getList() {
return list;
}
public void setList(Data list) {
this.list = list;
}
}
public class Data {
@ElementList(inline = true, name = "com.xyz.abc.VO.fruits", required = false)
private List<Fruits> fruits;
public List<Fruits> getfruits() {
return fruits;
}
public void setfruits(List<Fruits> fruits) {
this.fruits = fruits;
}
}
编辑1
public class Fruits{
@Element(required = false)
private int id;
@Element(required = false)
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
但是当我试图获得List<Fruits>
的大小时,它会给我NullPointerException。
如何更正我的代码?我正在使用Simple XML Serialization(org.simpleframework.xml。*)。