Configure Spring's MappingJacksonHttpMessageConverter

久未见 提交于 2020-01-04 05:36:18

问题


I am using MappingJacksonHttpMessageConverter in Spring MVC to automatically serialize objects like this:

@RequestMapping(value="/*/getAccount", method=RequestMethod.GET)
@ResponseBody
public Account getAccountAction() {
    Account account = accountService.getAccount();
    return account;
}

Is it possible to configure which properties of the object are serialized? In my example, Account has 3 collections as properties and serializing all these contents would result in a huge object tree. Here I only want to return the flat object.

Sincerely, Erik


回答1:


Did you already try to use the Jackson Annotations?

There is the Annotation @JsonIgnoreProperties that can be used to ignore a given list of properties for serialization on class level and there is @JsonIgnore to mark properties to ignore for serialization on field level.




回答2:


I could figure it out: Configure Jackson with annotatons, it is described in detail in the Jackson configuration.



来源:https://stackoverflow.com/questions/3747261/configure-springs-mappingjacksonhttpmessageconverter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!