为什么在camel-jackson-starter中,默认情况下autoDiscoverObjectMapper属性为false?

huangapple go评论69阅读模式
英文:

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

问题

目前我们正在将我们的应用从Camel 2.x迁移到Camel 3.x,并且遇到了一个问题,即JacksonDataFormat不再默认使用应用程序上下文中的ObjectMapper。相反,您需要提供一个属性camel.dataformat.json-jackson.auto-discover-object-mapper=true 来使此功能工作。我不明白为什么对于camel-jackson-starter 模块,默认情况下这不是true,这对我来说似乎是不合逻辑的。可能有人知道背后的原因。

英文:

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?

答案1

得分: 5

Apache Camel正在根据您的JacksonDataFormat定义修改ObjectMapper bean属性。如果一个看似不相关的DataFormat定义正在更改您在注册表中可能为应用程序的不同部分配置的单例ObjectMapper bean,这实在令人困惑。这对于某些开发人员来说可能是意料之外的,因此决定在启动过程中进行快速失败。

如果您使用了多个JacksonDataFormat定义,请不要设置camel.dataformat.json-jackson.auto-discover-object-mapper=true。您将看到一些奇怪的行为,这将非常难以调试。

参见CAMEL-14101

> json-jackson数据格式的当前默认行为是尝试在注册表中查找ObjectMapper实例,如果未找到则创建一个新实例。如果找到了一个实例,数据格式实例将根据其本地属性进行自定义,但由于相同的ObjectMapper实例可能在不同的json-jackson数据格式之间共享,这可能会导致不一致或不可预测的行为。

英文:

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.

huangapple
  • 本文由 发表于 2020年9月3日 19:22:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/63722602.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定