配置Spring的MappingJacksonHttpMessageConverter [英] Configure Spring's MappingJacksonHttpMessageConverter
问题描述
我在Spring MVC中使用 MappingJacksonHttpMessageConverter
来自动序列化这样的对象:
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;
}
是否可以配置对象的哪些属性被序列化?在我的示例中, Account
有3个集合作为属性,序列化所有这些内容将导致一个巨大的对象树。在这里,我只想返回扁平物体。
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.
此致
Erik
Sincerely, Erik
推荐答案
您是否已尝试使用杰克逊注释?
Did you already try to use the Jackson Annotations?
有注释 @ JsonIgnoreProperties ,可用于忽略类级别上的序列化的给定属性列表是 @JsonIgnore 来标记属性忽略字段级别的序列化。
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.
这篇关于配置Spring的MappingJacksonHttpMessageConverter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!