0

if I want to post json parameter to a url with jax-rs, how to receive the parameters in the back end and convert it into an integer array?

parameters:{"sbfIdList":[14]}

backend service(in java): I tried below , but feel no luck, I just got an empty array.

@POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Path("/delete")
    public String deleteSbc(@QueryParam("sbfIdList") List<Long> sbfIds,@Context HttpServletRequest request, @Context HttpServletResponse response) {
        return "";
    }

I request the backend service using POST method.

user1231111
  • 397
  • 2
  • 6
  • 16
  • Don't send it as query param. Just send it as the body of the request. You're making a POST request, which consumes JSON, so send it in the body so it can consume it :-) You'll need to wrap the list in a wrapper class, if you want the JSON to look like that – Paul Samsotha Mar 20 '15 at 23:57
  • hello peeskillet: How to send it in the body? I use it in a ajax invoking, not a standard form submission – user1231111 Mar 22 '15 at 00:06
  • That makes it even easier. [frontend](http://stackoverflow.com/q/12693947/2587435). [backend](http://stackoverflow.com/a/27170677/2587435). The dependency will be different depending on the jax-rs implementation you are using. For a generic dependency, use [this](https://github.com/FasterXML/jackson-jaxrs-providers). This is what's used by other implementations under the hood anyway, even the one I linked to. For help registering it, let me know what implementation of jax-rs you are using and show your app configuration – Paul Samsotha Mar 22 '15 at 01:24

0 Answers0