【问题标题】:How do I configure the default ObjectMapper?如何配置默认的 ObjectMapper?
【发布时间】:2019-09-22 01:17:26
【问题描述】:

在 light-4j 配置模块中,有一个 ObjectMapper 实例用于很多不同的地方。我有一个 Rest/GraphQL 混合应用程序,想要自定义默认的 ObjectMapper。最好的方法是什么?

【问题讨论】:

    标签: jackson objectmapper jackson-databind light-4j


    【解决方案1】:

    config 模块中的 ObjectMapper 实例是静态变量,使用静态块对其进行初始化。要覆盖配置,您可以创建一个启动挂钩来执行此操作。

    Config.getInstance().getMapper()
            .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
            .enable(MapperFeature.USE_STD_BEAN_NAMING)
            .setSerializationInclusion(JsonInclude.Include.ALWAYS)
            .setPropertyNamingStrategy(new CobraCase())
    

    【讨论】:

      猜你喜欢
      • 2017-05-01
      • 1970-01-01
      • 2020-06-05
      • 1970-01-01
      • 2014-10-17
      • 2020-04-15
      • 2020-08-23
      • 2018-03-14
      • 2010-10-23
      相关资源
      最近更新 更多