title: Jersey 2.1 - Consuming collection of POJO as JSON string
body: <p>I have a collection of entities (List) which I need to convert to/from json.</p>
  
  <p>The POJO:</p>
  
  <pre><code>public class Task {
  
      private Long id;
  
      private String title;
  
      private Boolean done;
      (...)
  }
  </code></pre>
  
  <p>Jersey produces the following result</p>
  
  <pre><code>[{"id":1,"title":"T1","done":false},{"id":2,"title":"T2","done":false}]
  </code></pre>
  
  <p>when I call the method:</p>
  
  <pre><code>@GET
  @Override
  @Produces("application/json")
  public List&lt;Task&gt; findAll() {
      (...)
      return tasks;
  }
  </code></pre>
  
  <p>So far so good.</p>
  
  <p>Now, I need to consume a similar JSON string. I assumed that the following method would do the trick:</p>
  
  <pre><code>@PUT
  @Consumes("application/json")
  public void save(List&lt;Task&gt; tasks) {
      (...)
  }
  </code></pre>
  
  <p>But instead I get the error below:</p>
  
  <pre><code>    SEVERE:   line 1:0 no viable alternative at input
  '"[{\"id\":1,\"title\":\"T1\",\"done\":true},{\"id\":2,\"title\":\"T2\",\"done\":false}]"'
  </code></pre>
  
  <p>What am I doing wrong? Is that even possible?</p>
  
  <p>Jersey's dependencies:</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;javax.ws.rs&lt;/groupId&gt;
      &lt;artifactId&gt;javax.ws.rs-api&lt;/artifactId&gt;
      &lt;version&gt;2.0&lt;/version&gt;
      &lt;scope&gt;provided&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
      &lt;artifactId&gt;jersey-container-servlet&lt;/artifactId&gt;
      &lt;version&gt;2.1&lt;/version&gt;
      &lt;scope&gt;provided&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.glassfish.jersey.media&lt;/groupId&gt;
      &lt;artifactId&gt;jersey-media-moxy&lt;/artifactId&gt;
      &lt;version&gt;2.1&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>Here is the web.xml configuration</p>
  
  <pre><code>&lt;servlet&gt;
      &lt;servlet-name&gt;Jersey Servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.glassfish.jersey.servlet.ServletContainer&lt;/servlet-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;jersey.config.server.provider.packages&lt;/param-name&gt;
          &lt;param-value&gt;my.rest.package&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 Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>