2

I want to get the list of variable parameters in JSON format of a POST request to a Jersey/Dropwizard backend.

Consider the json body in a POST request

{
 "tag1" : "tag1" ,
 "parameter" : 
    [ "key1" : "value1", 
      "key2" : "value2" ]
 }

Now the length of the parameters might vary so I was wondering how to access these key and values.

I tried the block

 @POST
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public Response insertJob(
      @PathParam("tag1") String tag1,
      @PathParam("parameter") List<Result> parameters
  ) {

    return Response.ok(resultList).build();

  }

but I get I get the error

No injection source found for a parameter of type public javax.ws.rs.core.Response ....

I was wondering what injection I am missing. by the way I use guice as an dependency injector

A.Dumas
  • 2,619
  • 3
  • 28
  • 51
  • see https://stackoverflow.com/questions/27341788/jersey-clientresponse-getentity-of-generic-type – Ori Marko Jun 12 '18 at 10:52
  • Can you post your configuration about Jersey and jackson ? – Dimitri Jun 18 '18 at 09:20
  • I don't think it's necessary any special config, try to use a POJO as in my answer instead of a PathParam (a path param is in the URL path) – maborg Jun 18 '18 at 20:01

1 Answers1

0

Jackson will do everything for if declare a simple POJO to map your JSON, just like this:

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public List<Result> insertJob(MySimplePOJO pojo ) {

    [...]

    return resultList;
}

class MySimplePOJO  {
    public String tag1;
    public List<Result> parameters;
}
maborg
  • 435
  • 5
  • 24