Can you configure Spring controller specific Jackson deserialization?

后端 未结 5 840
误落风尘
误落风尘 2020-12-15 16:42

I need to add a custom Jackson deserializer for java.lang.String to my Spring 4.1.x MVC application. However all answers (such as this) refer to configuring the ObjectMapper

5条回答
  •  隐瞒了意图╮
    2020-12-15 17:33

    You can define a POJO for each different type of request parameter that you would like to deserialize. Then, the following code will pull in the values from the JSON into the object that you define, assuming that the names of the fields in your POJO match with the names of the field in the JSON request.

    ObjectMapper mapper = new ObjectMapper(); 
    YourPojo requestParams = null;
    
    try {
        requestParams = mapper.readValue(JsonBody, YourPOJO.class);
    
    } catch (IOException e) {
        throw new IOException(e);
    }
    

提交回复
热议问题