Find @JsonSetter(nulls = Nulls.AS_EMPTY) on empty collection fields
Apache 2.0Find Map and Collection fields that carry @JsonSetter(nulls = Nulls.AS_EMPTY), are initialized with an empty collection, and are no longer hidden by @JsonIgnore on the field or its getter, or by a class level @JsonIgnoreProperties. In rewrite-jackson 1.17.0 through 1.28.0 the Jackson 2 to 3 migration replaced @JsonIgnore with @JsonSetter(nulls = Nulls.AS_EMPTY) on exactly these fields, which starts serializing properties that were deliberately hidden wherever the field is otherwise visible, such as through a getter. Run this recipe to audit repositories migrated with those versions; every match that should stay out of the JSON output needs @JsonIgnore restored, which the addJsonIgnore option does for you.
org. openrewrite. java. jackson. FindJsonSetterNullsAsEmptyCollectionsOptional
Add @JsonIgnore back to every match instead of only marking it, removing the @JsonSetter(nulls = Nulls.AS_EMPTY) that replaced it where nulls is its only argument. Only enable this once you have confirmed that none of the matches should be serialized. Defaults to false.
mod run . --recipe= org. openrewrite. java. jackson. FindJsonSetterNullsAsEmptyCollectionsInstall it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.