关于spring:在Spring Boot中添加一个二级ObjectMapper | 珊瑚贝

Add a secondary ObjectMapper in SpringBoot


我想在我的应用程序中几乎所有地方都使用默认的 ObjectMapper。
但是,我需要将特定请求发送给需要不同 ObjectMapper.

的第三方

有很多关于如何自定义默认映射器的帖子,但我找不到一篇解释如何在不替换默认映射器的情况下添加 ObjectMapper。

我尝试添加@Qualifier,为@Bean 添加一个名称,甚至创建一个继承ObjectMapper 的新类,但均无济于事。只要我添加任何类型的 ObjectMapper,默认的总是会被替换。

谁能提供一个例子来说明如何做到这一点?


不要让 Spring 管理它 – 只需在需要的地方进行新的操作即可。

当您提供 ObjectMapper bean 时,Jackson 的所有 Spring 自动配置都将退出。作为替代方案,您也可以在 Jackson2ObjectMapperBuilder 中使用 @Autowire,Jackson 自动配置使用它来创建默认的 ObjectMapper 实例。调用 Jackson2ObjectMapperBuilder#build 创建一个新的 ObjectMapper 实例。


来源:https://www.codenong.com/50690664/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9498.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?