Replacement for deprecated configuration

39 views
Skip to first unread message

David Wallace

unread,
Oct 11, 2022, 8:23:39 PM10/11/22
to jackson-user
I have an ObjectMapper which happens NOT to be a JsonMapper, that I receive from a component outside my control.

I would like to do something equivalent to objectMapper.disable(MapperFeature.USE_ANNOTATIONS); but this has been deprecated since 2.13.  The deprecation message tells me I should use JsonMapper.builder().disable(MapperFeature.USE_ANNOTATIONS).build(), but there is other configuration in my ObjectMapper that I need to preserve, and creating a whole new JsonMapper just won't work for me.  

If my original object were a JsonMapper, I imagine I could use ((JsonMapper) objectMapper).rebuild() to get a builder, then go from there.  But it's not.  

Any idea how I can disable a MapperFeature on an ObjectMapper in a non-deprecated way?

Tatu Saloranta

unread,
Oct 11, 2022, 8:27:38 PM10/11/22
to jackso...@googlegroups.com
No, unfortunately in this case I'd suggest you using `disable()` (or
`configure(MapperFeature)` but that seems deprecated as well).
It will not be removed until Jackson 3.0.

This is bit unfortunately as only 3.x has methods that would work in
your case: basically there is method `rebuild()` that can be called on
an
existing ObjectMapper, to allow construction of a new mapper with
different configuration.
This is unfortunately something that cannot be implemented reliably in
2.x so the only mechanism is the deprecated method.

-+ Tatu +-
Reply all
Reply to author
Forward
0 new messages