0

J'ai la réponse XML suivante d'un serveur GSA. Fondamentalement, il aParse GSA Liste XML avec Jackson

<GSP> 
<RES> 
    <M> 
    <R id=1> 
    </R> 
    <R id=2> 
    </R> 
</RES> 
</GSP> 

Comment puis-je analyser ce XML avec Jackson? Voici mon code

@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;} 

Ils ont tous les setters et les getters, ce n'est qu'un exemple. Je peux aller jusqu'à la RES, mais je ne peux pas obtenir le champ "resultados" rempli de la liste des résultats R. Cette erreur se produit:

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]) 

Répondre

0

trouvé la solution:

@JacksonXmlProperty(localName="R") 
@JacksonXmlElementWrapper(useWrapping = false) 
private List<ResultadoPagina> resultados;