0

I've created POST method:

    @POST
    @Path("/test")
    @JsonView({ TestView.class })
    public Response test(@Valid String testParameter) {
        return testController.doTest(testParameter);
    }

In request I'm sending one parameter:

{
  "testParameter": "Hello"
}

which I want to map to "testParameter" parameter in method. Class consumes / produces MediaType.APPLICATION_JSON. There's any available annotation which can allow me to get this parameter? Or do I have to remap the entire JSON(String) and get this value?

yaw
  • 303
  • 2
  • 11
  • there are multiple options described for example [here](https://stackoverflow.com/questions/12893566/passing-multiple-variables-in-requestbody-to-a-spring-mvc-controller-using-ajax) – micklesh May 06 '20 at 15:18

2 Answers2

0

All you need is a request object class with a single String field called testParameter. Replace the String parameter with this request object and retrieve your value from it.

Laugslander
  • 386
  • 2
  • 16
0

You can use Map<String, String> as requestbody if you don't want to create Class.

public Response test(Map<String, String> map) {
        return testController.doTest(map.get("testParameter"));
}
Eklavya
  • 17,618
  • 4
  • 28
  • 57