It is best to control at the business coding level instead of using the unified entrance MappingJackson2HttpMessageConverter. The control here is a one-size-fits-all approach, which will cause a headache when you need to return null in another scenario.
@RequestMapping(value="/{username}",method=RequestMethod.GET,params="json")
@ResponseBody
public User show(@PathVariable String username) {
User user = users.get(username);
return user == null ? new User() : user; // 这里只要为null的时候,返回一个空的对象即可
}
Set
jackson
Ignorenull
You can use trinocular when displaying the page. If the read value is null, the empty character will be output
It is best to control at the business coding level instead of using the unified entrance MappingJackson2HttpMessageConverter. The control here is a one-size-fits-all approach, which will cause a headache when you need to return null in another scenario.