This Question have 1 answers right now.

jersey (JSR-311), how to implement @POST in container pattern


from netbeans, i created a new REST webservice (using jersey), using the built-in wizards. in the container resource class, it created a stub,

public Response postJson(Identity identity) {
    return Response.status(Status.OK).entity(identity).build();

how to i POST to this? my understanding is that in need to post name=val pairs. what's jersey expecting here? how would i post json to this using say curl? here's what i tried,


DATA="{ \"id\": \"$1\", \"vcard\": \"$2\", \"location\": { \"latitude\": \"$3\", \"longitude\": \"$4\" } }"
echo "posting: $DATA"
curl --data-binary "${DATA}" -H "${HEADER}" "${URL}"

when i post this, and look at the identity object coming in, all fields are null? i suspect my json is incorrect. when i manually add an object to my container, then form a get, i see this result,

{"identities":{"id":"Foo Bar","vcard":"VCARD123","location":{"latitude":"-1.0","longitude":"-1.0"}}}

when i try to post the same thing, all fields all null. i also tried,

{"id":"Foo Bar","vcard":"VCARD123","location":{"latitude":"-1.0","longitude":"-1.0"}}

same result. ? thanks.



To send requests to this method using curl, you would have to use something like:

HEADER='--header Content-Type:application/json'
By : cheekoo

Video about jersey (JSR-311), how to implement @POST in container pattern