首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用Jackson解析GSA XML列表

用Jackson解析GSA XML列表
EN

Stack Overflow用户
提问于 2017-03-02 05:26:45
回答 1查看 187关注 0票数 0

我有以下来自GSA服务器的XML响应。基本上,它有

代码语言:javascript
复制
<GSP>
 <RES>
  <M>
  <R id=1>
  </R>
  <R id=2>
  </R>
 </RES>
</GSP>

我如何用Jackson解析这个XML?以下是我的代码

代码语言:javascript
复制
@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结果列表。出现以下错误:

代码语言:javascript
复制
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])
EN

回答 1

Stack Overflow用户

发布于 2017-03-02 20:40:25

找到解决方案:

代码语言:javascript
复制
@JacksonXmlProperty(localName="R")
@JacksonXmlElementWrapper(useWrapping = false)
private List<ResultadoPagina> resultados;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42542360

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档