@ResponseBody
@RequestMapping(value="/getUser")
public JSONObject getContent(@ReqeustBody User user)
Up here is my Controller code.
@Data
public class User{
private String username = "administrator";
private String password = "123456";
private Integer age = 18;
}
Up here is my User
class code.
{
"username":"admin",
"password":"000",
"age":""
}
When I POST
the JSON
above, I get the age
property to be null
.
I want Jackson
to deserialize the empty fields (""
or null
) in JSON
with default values.
Like this:
{
"username":"admin",
"password":"000",
"age":18
}
What should I do?