我正在开发一个带有 RESTful Web 服务的 GWT Web 应用程序。使用 Jackson 1.8 将 Web 服务的结果反序列化为 POJO。它适用于简单的字段。但是,当它尝试反序列化 POJO 列表时会失败。这是带有要反序列化的列表的 POJO:
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class DatosIndicadoresSVclaveDTO implements Serializable {
...
@XmlAttribute
@JsonDeserialize(contentAs = IdeologicoVOXDTO.class)
public List<IdeologicoVOXDTO> ideologicoVox;
...
//getter/setters
}
这是包含列表的 POJO
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class IdeologicoVOXDTO implements Serializable {
@XmlAttribute
private Integer numeroPalabra;
@XmlAttribute
private String palabra;
@XmlAttribute
private Integer categoria;
...
//getter/setters
}
JSON具有以下结构:
{datosIndicadoresSVclave: {
...
"ideologicoVox":[
{
"categoria":"1",
"numeroPalabra":"1",
"palabra":"abandonado",
...
},
{
"categoria":"2",
"numeroPalabra":"3",
"palabra":"hambre",
...
}
],
...
}
}
运行时,Web 服务的结果运行良好,但反序列化会打印此错误:
SEVERE: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at [Source: java.io.StringReader@10b61ad; line: 1, column: 580] (through reference chain: org.ull.etsii.client.dto.DatosIndicadoresSVclaveDTO["ideologicoVox"]) at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163) at org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:219) at org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:212)
Any idea?? Thanks!!