Jersey: liste des objets JSON

Je suis en train de récupérer dans mon Maillot de mise en œuvre de ressources de la classe post collection d'objets comme ceci:

@POST
@Path("/send")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String sendEmails(ArrayList<AnyEmail> email) {
    //emailManager.sendEmail(email);
    return "success";
}

J'ai le @XmlRootElement ci-dessus `AnyEmail.

Mais quand je suis à ce poste avec le REPOS outil client:

 emails : [
       {"body": "Testing the web service", "header": "Hi", "footer": "<br/>test"},
       {"body": "Testing the web service", "header": "Hi", "footer": "<br/>test"}
      ]

J'obtiens:

<html><head><title>Apache Tomcat/7.0.22 - Error report</title><style><!--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;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error () that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>javax.servlet.ServletException: Servlet execution threw an exception
</pre></p><p><b>root cause</b> <pre>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)

ÉDITÉ

Maintenant, j'ai essayé:

 "emails" : [
           {"body": "Testing the web service", "header": "Hi", "footer": "<br/>test"},
           {"body": "Testing the web service", "header": "Hi", "footer": "<br/>test"}
          ]

et j'obtiens:

    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)
  • Je crois que vous devriez envoyer tableau JSON au lieu de l'objet JSON. Essayez d'envoyer uniquement les [{...},{...}] segment de la demande de l'entité.
  • Quand je fais ce que je reçois: javax.ws.rs.WebApplicationException: javax.xml.bind.UnmarshalException - liés exception: [javax.xml.bind.UnmarshalException: inattendu élément (uri:"", locale:"le corps"). Éléments attendus sont <{}anyEmail>]
InformationsquelleAutor Dejell | 2011-10-04