Why autoDiscoverObjectMapper is false by default in camel-jackson-starter?
Asked Answered
B

1

6

Currently we are migrating our applications from Camel 2.x to Camel 3.x and faced an issue that JacksonDataFormat is not using an ObjectMapper from the application context by default anymore. Instead you need to provide a property camel.dataformat.json-jackson.auto-discover-object-mapper=true for this feature to work. I don't understand why this is not equal to true by default for the camel-jackson-starter module, this seems illogical to me. Probably someone knows the reason behind this?

Began answered 3/9, 2020 at 11:22 Comment(0)
O
5

Apache Camel is modifying ObjectMapper bean properties depending on your JacksonDataFormat definition. This is really confusing, if seemingly irrelevant DataFormat definition is changing your singleton ObjectMapper bean in registry, which you might have configured for different part of your application. This could be unexpected for some developers, so it has been decided to fail-fast during startup.

If you are using more than one JacksonDataFormat definition, never set camel.dataformat.json-jackson.auto-discover-object-mapper=true. You will see some strange behavior, which will be extremely hard to debug.

See CAMEL-14101:

The current default behaviour of the json-jackson data format is to try to lookup an ObjectMapper instance to the registry and if not found to create a new one. In case one is found, the data format instance does customize it according to its local properties but as the same ObjectMapper instance could be shared among different json-jackson data formats, it may lead to inconsistencies or unpredictable behaviors.

Obovate answered 4/9, 2020 at 0:27 Comment(2)
Thank you. This totally makes sense!Began
@Bedla, thanks for the answer. We also noticed that when auto-discover is switched off, default ObjectMapper is not discovering Jackson modules on classpath i.e. findAndRegisterModules(). Is is only allowed to specify them manually, what is the best way to make it do so?Sherleysherline

© 2022 - 2024 — McMap. All rights reserved.