我有来自 GSA 服务器的以下 XML 响应。基本上它有
<GSP>
<RES>
<M>
<R id=1>
</R>
<R id=2>
</R>
</RES>
</GSP>
如何用 Jackson 解析这个 XML?这是我的代码
@XmlRootElement(name = "GSP")
@JsonIgnoreProperties(ignoreUnknown = true)
public class RespuestaGSARoot {
@JacksonXmlProperty(localName = "RES")
private ResultadoBusqueda res;
}
@JacksonXmlRootElement(localName = "RES")
@JsonIgnoreProperties(ignoreUnknown = true)
public class ResultadoBusqueda {
@JacksonXmlProperty(localName = "M")
private int total;
@JacksonXmlProperty(localName = "R")
private List<ResultadoPagina> resultados;
}
@XmlRootElement(name = "R")
@JsonIgnoreProperties(ignoreUnknown = true)
public class ResultadoPagina {
@JacksonXmlProperty(localName = "U")
private String url;
@JacksonXmlProperty(localName = "T")
private String titulo;
@JacksonXmlProperty(localName = "S")
private String descripcion;}
他们都有 setter 和 getter,这只是一个例子。我可以一直到 RES,但我无法让“resultados”字段填满 R 结果列表。发生此错误:
com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class com.tm.buscador.domain.ResultadoPagina] from String value ('http://negocios.movistar.com.ar/tienda/lineas-y-planes/comunidad-negocios-full/'); no single-String constructor/factory method
at [Source: java.io.StringReader@642f9a77; line: 20, column: 99] (through reference chain: com.tm.buscador.domain.RespuestaGSARoot["RES"]->com.tm.buscador.domain.ResultadoBusqueda["R"]->java.util.ArrayList[0])