1

I'd like to do what's suggested here, namely:

objectMapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);

Unfortunately the Json mapping for my app is done entirely in xml, like this:

<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
  <property name="contentNegotiationManager" ref="contentNegotiationManager"/>
  <property name="defaultViews">
    <list>
      <bean name="jsonView" class="org.springframework.web.servlet.view.json.MappingJackson2JsonView"/>
    </list>
  </property>
</bean>

I don't need a custom ObjectMapper, I'd just like to be able to set the visibility of the default ObjectMapper that is used by MappingJackson2JsonView.

Is there any way to do this?

Cœur
  • 34,719
  • 24
  • 185
  • 251
Robert Bowen
  • 477
  • 1
  • 10
  • 23

1 Answers1

1

You can't change the default ObjectMapper used by MappingJackson2JsonView. It is stored in a private field and no methods exist to modify the object.

However, you can declare your own ObjectMapper bean and use MappingJackson2JsonView#setObjectMapper(ObjectMapper) to have the View use your custom ObjectMapper bean.

Sotirios Delimanolis
  • 263,859
  • 56
  • 671
  • 702