title: Parsing a complex JSON type in Jersey
body: <p>I'm using Jersey to create a servlet that takes a slightly complex JSON structure:</p>
  
  <pre><code>[
    {
      "name": "bob",
      "events": [
        {
          "type": "a",
          "value": "b"
        },
        {
          "type": "x",
          "value": "y"
        }
      ]
    },
    {
      "name": "alice",
      "events": [
      {
        "type": "one",
        "value": "two"
      },
      {
        "type": "three",
        "value": "four"
      }
      ]
    }
  ]
  </code></pre>
  
  <p>I have the following data classes:</p>
  
  <pre><code>public class Read
  {
    private String name;
    private ArrayList&lt;Event&gt; events;
    // Getters &amp; Setters
  }
  
  public class Event
  {
    private String type;
    private String value;
    // Getters &amp; Setters
  }
  </code></pre>
  
  <p>I want to be able to take in JSON and put it into an <code>ArrayList&lt;Read&gt;</code> object. I have the following code:</p>
  
  <pre><code>@Path("/postreads")
  @Consumes(MediaType.APPLICATION_JSON)
  public class PostReads
  {
    @POST
    @Path("/batch")
    public Response postReads(ArrayList&lt;Read&gt; reads)
    {
      for (Read read : reads)
      {
        System.out.println(read.toString());
      }
  
      return Response.status(200).entity("Success.").build();    
    }
  }
  </code></pre>
  
  <p>When I had it doing a simple object (the <code>Event</code>, with just two <code>String</code> properties), it worked fine. But adding the complexity of the <code>ArrayList</code>s killed it. Is there a way to automagically parse that JSON, or do I need to do it manually? It's a pretty open project at this point, so if I need to add an extra library, I can.</p>
  
  <p>The error I'm getting on the eclipse console:</p>
  
  <pre><code>Jun 03, 2014 2:44:01 PM com.sun.jersey.spi.container.ContainerRequest getEntity
  SEVERE: A message body reader for Java class java.util.ArrayList, and Java type java.util.ArrayList&lt;com.project.postevents.Event&gt;, and MIME media type application/json was not found.
  The registered message body readers compatible with the MIME media type are:
  application/json -&gt;
    com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$App
    com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$App
    com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$App
  */* -&gt;
    com.sun.jersey.core.impl.provider.entity.FormProvider
    com.sun.jersey.core.impl.provider.entity.StringProvider
    com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
    com.sun.jersey.core.impl.provider.entity.FileProvider
    com.sun.jersey.core.impl.provider.entity.InputStreamProvider
    com.sun.jersey.core.impl.provider.entity.DataSourceProvider
    com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
    com.sun.jersey.core.impl.provider.entity.ReaderProvider
    com.sun.jersey.core.impl.provider.entity.DocumentProvider
    com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader
    com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader
    com.sun.jersey.core.impl.provider.entity.SourceProvider$DOMSourceReader
    com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$General
    com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
    com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
    com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General
    com.sun.jersey.core.impl.provider.entity.EntityHolderReader
    com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$General
    com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$General
  </code></pre>
  
  <p>Edit: The comma after the square bracket was a typo. The incoming JSON validates.</p>