Java RESTeasy/JAXB的JSON解析错误

Java RESTeasy/JAXB的JSON解析错误,java,json,rest,jaxb,resteasy,Java,Json,Rest,Jaxb,Resteasy,我正在尝试调用iTunes REST服务,该服务通过RESTeasy客户端返回iTunes中定义的流派信息。此调用返回的JSON对象如下所示: { "35":{ "name":"iPod Games", "id":"35", "url":"https://itunes.apple.com/us/genre/ipod-games/id35" }, "36":{ "name":"App Store", "id":"36",

我正在尝试调用iTunes REST服务,该服务通过RESTeasy客户端返回iTunes中定义的流派信息。此调用返回的JSON对象如下所示:

{
   "35":{
      "name":"iPod Games",
      "id":"35",
      "url":"https://itunes.apple.com/us/genre/ipod-games/id35"
   },
   "36":{
      "name":"App Store",
      "id":"36",
      "url":"https://itunes.apple.com/us/genre/ios/id36?mt=8"
   }
}
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@JsonIgnoreProperties(ignoreUnknown = true)
public class ITunesGenre implements Serializable {

    private static final long serialVersionUID = 4330727214147295490L;

    @XmlElement
    private String name = null;

    @XmlElement
    private String id = null;

   ...

}
我定义了如下响应对象模型:

{
   "35":{
      "name":"iPod Games",
      "id":"35",
      "url":"https://itunes.apple.com/us/genre/ipod-games/id35"
   },
   "36":{
      "name":"App Store",
      "id":"36",
      "url":"https://itunes.apple.com/us/genre/ios/id36?mt=8"
   }
}
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@JsonIgnoreProperties(ignoreUnknown = true)
public class ITunesGenre implements Serializable {

    private static final long serialVersionUID = 4330727214147295490L;

    @XmlElement
    private String name = null;

    @XmlElement
    private String id = null;

   ...

}
然而,当我通过我的RESTeasy客户端进行调用时,我得到了序列化错误。我相信这是因为这不是一个真正的对象列表或数组。相反,似乎每个条目上都有一个“标识符”(在上面的示例中,是“35”或“36”)

给定这样一个JSON对象,我如何映射它,以便RESTeasy客户端可以对其进行反序列化?我以前从未遇到过这种格式的对象。我显然不能硬编码每个标识符,因为会有几个标识符,它们可能会发生变化

您可以通过查看此调用返回的完整JSON对象(相当大)。您将看到此对象结构贯穿于此对象,而不是使用简单的对象列表或数组


有什么想法吗?我非常感谢您提供的任何帮助。

响应是一个映射,因此根元素不是您的iTunesGene类,而是映射。我想很清楚如何修改响应对象。

我想它可能看起来像这样(尽管我还没有测试过它)

@XmlRootElement
公共类响应实现可序列化
{
公众回应({
}
private java.util.Map genres=new java.util.HashMap();
}
公共类类型实现了可序列化{
私有静态最终长serialVersionUID=433072714147295490L;
公共体裁(){
}
@XmlElement
私有字符串名称=null;
@XmlElement
私有字符串id=null;
...
}

请在服务器上发布您收到的确切错误消息?恐怕这无法用JAXB表达。我会选择
org.json.JSONObject
就是这样。我将客户机上的返回对象更改为Map,它就像一个符咒一样工作。谢谢