我是序列化和反序列化 JSON 的新手。
我有值的字符串
String json = [{"Area":"LoremIpsum","Quantity":1500,"isSubArea":false},
{"Area":"LoremIpsum","Quantity":700,"isSubArea":false}];
我想反序列化,我使用杰克逊的 ObjectMapper 反序列化
ObjectMapper mapper = new ObjectMapper();
List<DeserializeJSON> agentsList = mapper.readValue(json,new TypeReference<List<DeserializeJSON>>() {});
我的反序列化类
public class DeserializeJSON {
String Area;
Integer Quantity = 0;
boolean isSubArea = false;
public String getArea() {
return Area;
}
public void setArea(String Area) {
this.Area = Area;
}
public Integer getQuantity() {
return Quantity;
}
public void setQuantity(Integer Quantity) {
this.Quantity = Quantity;
}
public boolean isSubArea() {
return isSubArea;
}
public void setSubArea(boolean isSubArea) {
this.isSubArea = isSubArea;
}
}
但我收到错误
Unrecognized field "Area" (Class DeserializeJSON), not marked as ignorable at [Source: java.io.StringReader@2acf7a; line: 1, column: 11] (through reference chain: DeserializeJSON["Area"])