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
  • 37,241
  • 25
  • 195
  • 267
Robert Bowen
  • 487
  • 2
  • 13
  • 24

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
  • 274,122
  • 60
  • 696
  • 724