Jersey, how to POST a list of JSON objects?

前端 未结 5 1360
栀梦
栀梦 2021-02-05 22:25

I am building a RESTful web-service in Java using Jersey 1.11, and have problems implementing a method which consumes a list of JSON-ised entities. The single instance method wo

5条回答
  •  走了就别回头了
    2021-02-05 22:59

    This is valid JSON for an array:

    {"elements": [
            {"field1" : value1, "field2" : value2}, 
            {"field1" : value3, "field2" : value4},
            ...]
    };
    

    (see here for an example)

    You don't need to send text, you can send it as JSON. Also your MyEntity should have @XmlRootElement on it (see here, section 5.2 for an example).

    You don't need PathParam in your arguments, someParam is available when the request is posted if you leave the @Path("/some-path/{someParam}") in your method signature .

提交回复
热议问题