Spring Boot忽略ObjectMapper模块 [英] Spring Boot ignore ObjectMapper module

查看:403
本文介绍了Spring Boot忽略ObjectMapper模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在应用程序上下文中,我已经注册了一个ObjectMapper模块:

In application context I have registered an ObjectMapper module:

@Bean
public SimpleModule jsr310Module() {
    final SimpleModule module = new SimpleModule();
    module.addSerializer(new LocalDateSerializer());
    module.addDeserializer(LocalDate.class, new LocalDateDeserializer());
    return module;
}

我试图调试并加载它(或者至少是方法 public void setupModule(SetupContext context)在启动时执行)
但是当我调用一个返回带有LocalDate的对象的rest API时,我的反序列化器将被忽略。

I tried to debug and it is loaded (or at least the method public void setupModule(SetupContext context) is execute on boot) but when I call a rest API that return an object with a LocalDate my deserializer is ignored.

一些解决问题的提示?

推荐答案

根据 Spring Boot文档,要配置ObjectMapper,您可以自己定义bean并使用 @Bean @Primary 对其进行注释。在那里你可以注册模块。或者你可以添加一个类型为 Jackson2ObjectMapperBuilder 的bean,你可以自定义ObjectMapper。

According to the Spring Boot documentation, to configure the ObjectMapper you can either define the bean yourself and annotate it with @Beanand @Primary. There you can register the module. Or you can add a bean of type Jackson2ObjectMapperBuilderwhere you can customize the ObjectMapper.

这篇关于Spring Boot忽略ObjectMapper模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆