开发者

Configure Spring's MappingJacksonHttpMessageConverter

开发者 https://www.devze.com 2023-01-17 05:35 出处:网络
I am using MappingJacksonHttpMessageConverter in Spring MVC to automatically serialize objects like this:

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 serializin开发者_运维技巧g all these contents would result in a huge object tree. Here I only want to return the flat object.

Sincerely, Erik


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号