Spring MVC, deserialize single JSON?

前端 未结 2 869
南笙
南笙 2021-01-05 06:09

How can I easily separate JSON values that are sent in the same request?

Given that I POST a JSON to my server:

{\"first\":\"A\",\"second\":\"B\"}
<         


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-01-05 07:01

    POJO

    public class Input {
        private String first;
        private String second;
    
        //getters/setters
    }
    

    ...and then:

    public void handleRequest(@RequestBody Input input)
    

    In this case you need Jackson to be available on the CLASSPATH.

    Map

    public void handleRequest(@RequestBody Map input)
    

提交回复
热议问题