Mapping JSON Response into Object with JAX-RS and JAXB
<p>I'm trying to map the response I get from a remote service into an object. For the client I'm using JAX-RS annotated interface: </p>

<pre><code>@GET
@Path("/content/example.data")
@Produces(MediaType.APPLICATION_JSON)
@Cacheable("my-data")
Items getInfo(
        @PathParam("country") String country,
        @PathParam("language") String language);
</code></pre>

<p>The response comes in this format, as a JSON list of objects:</p>

<pre><code>[
  {
    "code": "01",
    "name": "Item1",
    "description": "Description for item1",
    "show": true
  },
  {
    "code": "02",
    "name": "Item2",
    "description": "Description for item2",
    "show": true
  }
]
</code></pre>

<p>And the class I'm trying to map into is: </p>

<pre><code>@XmlRootElement
public class Items {

    @XmlElementWrapper
    List&lt;Item&gt; items;

    public List&lt;Item&gt; getItems() {
        return items;
    }

    public void setItems(List&lt;Item&gt; items) {
        this.items = items;
    }

}


@XmlRootElement
public class Item {

    @XmlElement(name = "code")
    private String code;
    @XmlElement(name = "name")
    private String name;
    @XmlElement(name = "description")
    private String description;
    @XmlElement(name = "show")
    private Boolean show;

    public Item(){

    }

    //...getters/setters
}
</code></pre>

<p>It always returns an Items instance with an empty list of items. Any ideas?</p>

<p><strong>UPDATE</strong></p>

<p>Changing it to: </p>

<pre><code>List&lt;Item&gt; getInfo(
            @PathParam("country") String country,
            @PathParam("language") String language);
</code></pre>

<p>returns <code>ArrayList&lt;ElementNSImpl&gt;</code> where I can see the properties by navigating through the nodes. But it doesn't map it to the Item class.</p>

<p>I changed the response to be only an object instead of an array on the server and changed the interface to: </p>

<pre><code>Item getInfo(
            @PathParam("country") String country,
            @PathParam("language") String language);
</code></pre>

<p>and it maps the object perfectly, so the problem must be when mapping objects inside a list.</p>