Note that there are some explanatory texts on larger screens.

plurals
  1. POError passing single element JSON array in Jersey 1.5
    primarykey
    data
    text
    <p>I have a Books class with ArrayList of BookMeta objects , the name of the arraylist is bookList.</p> <p>If the bookList holds more than one BookMeta, it works good for the clients as they receive an array. But if there is only one BookMeta object in bookList, they dont receive an array, instead they get one element. I took the following workaround for forcing the output to be one array :</p> <pre><code>@Provider public class JaxbContextResolver implements ContextResolver&lt;JAXBContext&gt; { private JAXBContext context; private Class[] types = {BookMeta.class, Books.class}; public JaxbContextResolver() throws Exception { this.context = new JSONJAXBContext( JSONConfiguration.mapped().arrays("bookList").build(), types); } public JAXBContext getContext(Class&lt;?&gt; objectType) { for (Class type : types) { if (type == objectType) { return context; } } return null; } } </code></pre> <p>Still I am not getting arrays. What else should I do ? Do I need to explicitly register the Provider classes ? I read somewhere they are automatically detected.</p> <p>Thanks.</p> <p>Edit : I am using Tomcat 6, and my web.xml looks like :</p> <pre><code>&lt;servlet&gt; &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt; &lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt; &lt;param-value&gt;resources&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt; &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre>
    singulars
    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