0
我從GSA服務器收到以下XML響應。 基本上它有用Jackson解析GSA XML列表
<GSP>
<RES>
<M>
<R id=1>
</R>
<R id=2>
</R>
</RES>
</GSP>
我如何解析這個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和getters,這只是一個例子。我可以去RES,但我不能得到充滿R結果列表的字段「resultados」。 發生此錯誤:
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: [email protected]; line: 20, column: 99] (through reference chain: com.tm.buscador.domain.RespuestaGSARoot["RES"]->com.tm.buscador.domain.ResultadoBusqueda["R"]->java.util.ArrayList[0])