如何将 Jackson PropertyNamingStrategy 与 Immutables 库一起使用

How to use Jackson PropertyNamingStrategy with Immutables library

我正在与 Jackson 一起使用 https://immutables.github.io/ 库。 我希望我的 class 能够被 Jackson 序列化。我想使用自定义 PropertyNamingStrategy(配置为 com.fasterxml.jackson.databind.ObjectMapper 使用 mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);

不幸的是,Immutables 库将 @JsonProperty("propertyName") 放在生成代码的每个字段中。这会覆盖在映射器级别定义的 PropertyNamingStrategy(或在 class 级别,使用 @com.fasterxml.jackson.databind.annotation.JsonNaming 注释)。

是否可以让 Immutables 库停止为每个字段添加 属性 名称(使用 org.immutables.value.Value.Style 或类似方法)?

我已经有了解决方法,在每个 属性 处放置 @JsonProperty(没有值),但我对此并不满意。

样式 属性 forceJacksonPropertyNames=false 不会强制 属性 名称为特定字符串。它适用于在 class 级别和映射器级别配置的命名策略。

此处提供样式介绍:http://immutables.github.io/style.html

您可以在问题中阅读有关此设置的一些背景信息:https://github.com/immutables/immutables/issues/431 https://github.com/immutables/immutables/issues/353