且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在spring-boot中强制使用Jackson2ObjectMapperBuilder?

更新时间:2022-05-17 00:06:16

这是 Spring的自定义 ObjectMapper 的文档,这是它说的是:

Here's Spring's documentation for customised ObjectMapper, this is what it says:


如果你想完全替换默认的ObjectMapper,
定义一个 @该类型的Bean 并将其标记为 @Primary ,或者,如果您更喜欢
基于构建器的方法,请定义Jackson2ObjectMapperBuilder
@Bean 。请注意,在任何一种情况下,这都将禁用ObjectMapper的所有
自动配置。

If you want to replace the default ObjectMapper completely, either define a @Bean of that type and mark it as @Primary, or, if you prefer the builder-based approach, define a Jackson2ObjectMapperBuilder @Bean. Note that in either case this will disable all auto-configuration of the ObjectMapper.

如果定义 ObjectMapper bean没有帮助,您可以尝试定义 Jackson2ObjectMapperBuilder bean吗?

If defining ObjectMapper bean does not help, could you try defining Jackson2ObjectMapperBuilder bean instead?

另外,您是否可以尝试将bean定义为使用 @Configuration 注释的类?

Also, could you try defining the beans into a class annotated with @Configuration?