Note that there are some explanatory texts on larger screens.

plurals
  1. POJersey serialize empty list and single element list as an array
    primarykey
    data
    text
    <p>Since there is a probelm with serialization an emplty list and single element list in Jersey. I tried to fix it by adding JAXBContextResolver class. The goal is to return JSON object thant contains JSON array to my Android application in all cases (if it returns 0 element or 1 element or more than 1). But my JSON data don't look the same. And I get an error in my android application <code>Expected BEGIN_OBJECT but was BEGIN_ARRAY</code> I would greatly appreciate your help. Thanks in advance</p> <pre><code>@Provider public class JAXBContextResolver implements ContextResolver&lt;JAXBContext&gt; { private JAXBContext context; private final Set&lt;Class&gt; types; // pojo class private Class[] ctypes = { Workitem.class, Project.class, User.class }; public JAXBContextResolver() throws Exception { NaturalBuilder builder = JSONConfiguration.natural(); //assure the rootelement name appears in the json structure builder.rootUnwrapping(false); this.types = new HashSet(Arrays.asList(ctypes)); // json configuration this.context = new JSONJAXBContext(builder.build(), ctypes); } @Override public JAXBContext getContext(Class&lt;?&gt; objectType) { return (types.contains(objectType)) ? context : null; } } </code></pre> <p>My JSON data look like this when I set <code>builder.rootUnwrapping(true);</code> </p> <pre><code>[ { "assignedTo": "assignee1", "businessKey": "Key1", "createdBy": "createdBy1", "description": "description1" } ] </code></pre> <p>But I want it to be like this to solve my problem in Android side :</p> <pre><code>{ "project": [ { "assignedTo": "assignee1", "businessKey": "Key1", "createdBy": "createdBy1", "description": "description1" } ] } </code></pre> <p>I added <code>@JsonRootName(value = "project")</code> to my My Project class in order to fix my problem but I get this error but I don't khow how to solve it please I need help </p> <pre><code>Multiple markers at this line - JsonRootName cannot be resolved to a type - The attribute value is undefined for the annotation type JsonRootName </code></pre> <p>My Project class is like this :</p> <pre><code>@XmlRootElement @JsonRootName(value = "project") public class Project implements Serializable { private static final long serialVersionUID = 1L; private String description; private String businessKey; private String createdBy; private String assignedTo; public Project() { } // getter and setter method } </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