title: Jersey: list of JSON objects
body: <p>I am trying to retrieve in my Jersey implementation resource class post collection of objects like this:</p>
  
  <pre><code>@POST
  @Path("/send")
  @Consumes({ MediaType.APPLICATION_JSON })
  @Produces({ MediaType.APPLICATION_JSON })
  public String sendEmails(ArrayList&lt;AnyEmail&gt; email) {
      //emailManager.sendEmail(email);
      return "success";
  }
  </code></pre>
  
  <p>I have the <code>@XmlRootElement</code> above `AnyEmail.</p>
  
  <p>However when I post like this with REST client tool:</p>
  
  <pre><code> emails : [
         {"body": "Testing the web service", "header": "Hi", "footer": "&lt;br/&gt;test"},
         {"body": "Testing the web service", "header": "Hi", "footer": "&lt;br/&gt;test"}
        ]
  </code></pre>
  
  <p>I get: </p>
  
  <pre><code>&lt;html&gt;&lt;head&gt;&lt;title&gt;Apache Tomcat/7.0.22 - Error report&lt;/title&gt;&lt;style&gt;&lt;!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--&gt;&lt;/style&gt; &lt;/head&gt;&lt;body&gt;&lt;h1&gt;HTTP Status 500 - &lt;/h1&gt;&lt;HR size="1" noshade="noshade"&gt;&lt;p&gt;&lt;b&gt;type&lt;/b&gt; Exception report&lt;/p&gt;&lt;p&gt;&lt;b&gt;message&lt;/b&gt; &lt;u&gt;&lt;/u&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;description&lt;/b&gt; &lt;u&gt;The server encountered an internal error () that prevented it from fulfilling this request.&lt;/u&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;exception&lt;/b&gt; &lt;pre&gt;javax.servlet.ServletException: Servlet execution threw an exception
  &lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;root cause&lt;/b&gt; &lt;pre&gt;java.lang.Error: Error: could not match input
      com.sun.jersey.json.impl.reader.JsonLexer.zzScanError(JsonLexer.java:491)
      com.sun.jersey.json.impl.reader.JsonLexer.yylex(JsonLexer.java:736)
  </code></pre>
  
  <p><strong>EDITED</strong><br>
  Now I tried:</p>
  
  <pre><code> "emails" : [
             {"body": "Testing the web service", "header": "Hi", "footer": "&lt;br/&gt;test"},
             {"body": "Testing the web service", "header": "Hi", "footer": "&lt;br/&gt;test"}
            ]
  </code></pre>
  
  <p>and I get:</p>
  
  <pre><code>    SEVERE: Servlet.service() for servlet [Jersey Web Application] in context with path [/API] threw exception
  java.lang.ArrayIndexOutOfBoundsException: -1
      at java.util.ArrayList.get(ArrayList.java:324)
      at com.sun.jersey.json.impl.reader.JsonXmlStreamReader.valueRead(JsonXmlStreamReader.java:165)
      at com.sun.jersey.json.impl.reader.JsonXmlStreamReader.readNext(JsonXmlStreamReader.java:330)
  </code></pre>