MappingJackson2HttpMessageConverter objConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper objMapper = new ObjectMapper();
objMapper.setVisibility(PropertyAccessor.FIELD, Visibility.NONE);
objMapper.getSerializationConfig().withView(View.class);
objConverter.setObjectMapper(objMapper);
objConverter.getObjectMapper().getSerializationConfig().withView(View.class);
之后
objMapper.getSerializationConfig()
与使用方法SerializationConfig
(..).withView(..)
具有不同的引用
看起来新的SerializationConfig
未应用于objMapper
热点解决这个问题?我的@JsonView注释也无效。
fasterxml.jackson 2.3.0
答案 0 :(得分:0)
基于Javier Molla的链接答案:
您应该在ObjectMapper上使用.configure()
,最好重复使用映射器。
final ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
mapper.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false);
mapper.setSerializationInclusion(Include.NON_NULL);
您可以将序列化功能放在静态块中并重复使用mapper =>性能提升。