Note that there are some explanatory texts on larger screens.

plurals
  1. POJersey JSON marshalling of nested generic produces null
    primarykey
    data
    text
    <p>Having an issue trying to marshall into JSON a HashMap nested in a List using Jersey 1.11.</p> <p>Here's a snippet of a Jersey endpoint which produces MediaType.APPLICATION_JSON via the returned Response object:</p> <p><strong>DataDTO.java</strong></p> <pre><code>@XmlRootElement public class DataDTO { ... private List&lt;GenericEntity&lt;HashMap&lt;String, String&gt;&gt; dataHierarchy; public List&lt;GenericEntity&lt;HashMap&lt;String, String&gt;&gt; getDataHierarchy() { return dataHierarchy; } public void setDataHierarchy(List&lt;GenericEntity&lt;HashMap&lt;String, String&gt;&gt; dh) { dataHierarchy = dh; } } </code></pre> <p><strong>Jersey resource class:</strong></p> <pre><code>@Get @Produces(MediaType.APPLICATION_JSON) @Path("/summary") public Response getSummary() { .... DataDTO dto = new DataDTO(); List&lt;GenericEntity&lt;HashMap&lt;String,String&gt;&gt;&gt; genericEntityList = new ArrayList&lt;&gt;(); for (HashMap&lt;String, String&gt; hashMapEntity : summary.getDataHierarchy()) { GenericEntity&lt;HashMap&lt;String, String&gt;&gt; genericEntity = new GenericEntity&lt;HashMap&lt;String, String&gt;&gt;(hashMapEntity) {}; genericEntityList.add(genericEntity); } dto.setDataHierarchy(genericEntityList); return Response.ok(dto).build(); } </code></pre> <p>The DTO is part of the 'natural class set' and its JAXBContext resolver context is configured to use natural notation and root unwrapping as so:</p> <pre><code>new JSONJAXBContext(JSONConfiguration.natural().rootUnwrapping(true).build(), naturalClassSet.toArray(new Class[naturalClassSet.size()])); </code></pre> <p>When, for example there are 5 entries in the list, the response JSON ends up looking like so:</p> <pre><code>{"dataHierarychy":[null, null, null, null, null]} </code></pre> <p>I've also tried changing the dataHierarchy property of DataDTO so that each generic data structure is wrapped in a GenericEntity:</p> <pre><code>private GenericEntity&lt;List&lt;GenericEntity&lt;HashMap&lt;String,String&gt;&gt;&gt;&gt; </code></pre> <p>This results in simply:</p> <pre><code>{"dataHierarychy":null} </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload