0
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);

after

objMapper.getSerializationConfig()

has different reference than SerializationConfig created with method (..).withView(..)

It look as if new SerializationConfig is not applied to objMapper

Hot to solve this issue? Also my @JsonView annotations are not working.

fasterxml.jackson 2.3.0

Anthon
  • 69,918
  • 32
  • 186
  • 246
kxyz
  • 802
  • 1
  • 9
  • 32
  • Leave out tabs from formatting, that doesn't work well here. Also backquote inline code to increase visual recognition of code. Readability increases the chance of someone understanding your problem, and thus of an answer. – Anthon Mar 06 '15 at 07:50
  • Maybe this question helps you: http://stackoverflow.com/a/21054896/4576054 – Javi Mollá Mar 06 '15 at 08:39

1 Answers1

0

Based on the linked answer by Javier Molla:

You should use .configure() on your ObjectMapper and preferably reuse the mapper.

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);

You can put the serialization features in a static block and reuse the mapper => performance boost.

Community
  • 1
  • 1
sebster
  • 1,322
  • 2
  • 18
  • 29