我使用以下代码来实现上述但不起作用。请指南。
class ItemAttributes {
@Element(name = "Binding")
private String binding;
@Element(name = "Brand")
private String brand;
@Element(name = "Color")
private String color;
@Element(name = "EAN")
private String ean;
@Element(name = "EANList")
private EANList eanLists;
@Element(name = "Feature")
private List<String> feature;
}
错误:
org.simpleframework.xml.core.InstantiationException:不能 为字段'feature'envate实例化接口java.util.List java.util.List ItemAttributes.feature
改造中的我的XML日志响应:
"ItemAttributes": {
"Binding": "",
"Brand": "",
"Color": "",
"EAN": "",
"EANList": {
"EANListElement": ""
},
"Feature": ["","",""]
}
答案 0 :(得分:2)
我自己也找到了答案。解决方案(至少在我的情况下)是定义一个可以实例化的具体类型,而不是一个抽象类型。
@ElementList(name = "Feature")
private ArrayList<String> feature;
而不是
@Element(name = "Feature")
private List<String> feature;