简体   繁体   中英

Getting Post Data at Jersey

Somebody will post data as like that:

curl http://localhost:8080/uno/json -H 'Content-type:application/json' -d '
[
 {"id" : "TestDoc2", "hry" : "go"}
]'

How can I get that data within my Jersey based Java application?

Something like this:

Here is a bean to match the JSON you posted:

public class Foo {
  String id;
  String hry;

  ...getters and setters...
}

And a basic resource listening on the paths your example is trying to curl :

@Path("/uno")
public class MyResource {

  @POST
  @Path("/json")
  @Consumes(MediaType.APPLICATION_JSON)  
  public void postJSON(List<Foo> fooList) {
    ...do whatever you need to
  }
}

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM