From d5a1ee7238b18e1d0eeac70c66e14429b5567f56 Mon Sep 17 00:00:00 2001 From: Rune Flobakk Date: Fri, 5 Sep 2025 21:12:35 +0200 Subject: [PATCH 1/5] Add JsonInclude.Value constants Equivalent to the enum values of JsonInclude.Include. See also discussion here: https://github.com/FasterXML/jackson-databind/discussions/5294 --- .../jackson/annotation/JsonInclude.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java b/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java index 83bd9508..53b4c851 100644 --- a/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java +++ b/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java @@ -262,6 +262,49 @@ public static class Value { private static final long serialVersionUID = 1L; + /** + * Value that indicates that property is to be always included, + * independent of value of the property. + */ + public final static Value ALL_ALWAYS = Value + .construct(Include.ALWAYS, Include.ALWAYS); + + /** + * Value that indicates that only properties with non-null + * values are to be included. + */ + public final static Value ALL_NON_NULL = Value + .construct(Include.NON_NULL, Include.NON_NULL); + + /** + * Value that indicates that properties are included unless their value + * is: + * + * This option is mostly used to work with "Optional"s (Java 8, Guava). + */ + public final static Value ALL_NON_ABSENT = Value + .construct(Include.NON_ABSENT, Include.NON_ABSENT); + + /** + * Value that indicates that only properties with null value, + * or what is considered empty, are not to be included. + * See {@link Include#NON_EMPTY} for further details. + */ + public final static Value ALL_NON_EMPTY = Value + .construct(Include.NON_EMPTY, Include.NON_EMPTY); + + /** + * The equivalent to {@link Include#NON_DEFAULT} for specifying + * inclusion of non-defaults for both values and content. + */ + public final static Value ALL_NON_DEFAULT = Value + .construct(Include.NON_DEFAULT, Include.NON_DEFAULT); + protected final static Value EMPTY = new Value(Include.USE_DEFAULTS, Include.USE_DEFAULTS, null, null); From 2cb264bb57849c6e19d39fa4802db60ce3f922f3 Mon Sep 17 00:00:00 2001 From: Rune Flobakk Date: Sat, 6 Sep 2025 00:19:01 +0200 Subject: [PATCH 2/5] Add missing version spec in javadoc: 2.21 --- .../com/fasterxml/jackson/annotation/JsonInclude.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java b/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java index f1cb79f3..5457a87d 100644 --- a/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java +++ b/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java @@ -271,6 +271,8 @@ public static class Value /** * Value that indicates that property is to be always included, * independent of value of the property. + * + * @since 2.21 */ public final static Value ALL_ALWAYS = Value .construct(Include.ALWAYS, Include.ALWAYS); @@ -278,6 +280,8 @@ public static class Value /** * Value that indicates that only properties with non-null * values are to be included. + * + * @since 2.21 */ public final static Value ALL_NON_NULL = Value .construct(Include.NON_NULL, Include.NON_NULL); @@ -292,6 +296,8 @@ public static class Value * that would not deference to a non-null value. * * This option is mostly used to work with "Optional"s (Java 8, Guava). + * + * @since 2.21 */ public final static Value ALL_NON_ABSENT = Value .construct(Include.NON_ABSENT, Include.NON_ABSENT); @@ -300,6 +306,8 @@ public static class Value * Value that indicates that only properties with null value, * or what is considered empty, are not to be included. * See {@link Include#NON_EMPTY} for further details. + * + * @since 2.21 */ public final static Value ALL_NON_EMPTY = Value .construct(Include.NON_EMPTY, Include.NON_EMPTY); @@ -307,6 +315,8 @@ public static class Value /** * The equivalent to {@link Include#NON_DEFAULT} for specifying * inclusion of non-defaults for both values and content. + * + * @since 2.21 */ public final static Value ALL_NON_DEFAULT = Value .construct(Include.NON_DEFAULT, Include.NON_DEFAULT); From ab7a5cf1b836a1581f5fd647c2667160218df080 Mon Sep 17 00:00:00 2001 From: Rune Flobakk Date: Sat, 6 Sep 2025 01:01:58 +0200 Subject: [PATCH 3/5] Add javadoc details about value inclusion The constants specify the same JsonInclude.Include for inclusion of values both on Java object level, as well when contained in an object reference (e.g. an AtomicReference). --- .../jackson/annotation/JsonInclude.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java b/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java index 5457a87d..4bf411e6 100644 --- a/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java +++ b/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java @@ -271,6 +271,11 @@ public static class Value /** * Value that indicates that property is to be always included, * independent of value of the property. + *

+ * This will specify the same setting for including a value both + * on Java object level as well as when contained + * in an object reference (see {@link JsonInclude} for further + * details on this distinction) * * @since 2.21 */ @@ -280,6 +285,11 @@ public static class Value /** * Value that indicates that only properties with non-null * values are to be included. + *

+ * This will specify the same setting for including a value both + * on Java object level as well as when contained + * in an object reference (see {@link JsonInclude} for further + * details on this distinction) * * @since 2.21 */ @@ -296,6 +306,11 @@ public static class Value * that would not deference to a non-null value. * * This option is mostly used to work with "Optional"s (Java 8, Guava). + *

+ * This will specify the same setting for including a value both + * on Java object level as well as when contained + * in an object reference (see {@link JsonInclude} for further + * details on this distinction) * * @since 2.21 */ @@ -306,6 +321,11 @@ public static class Value * Value that indicates that only properties with null value, * or what is considered empty, are not to be included. * See {@link Include#NON_EMPTY} for further details. + *

+ * This will specify the same setting for including a value both + * on Java object level as well as when contained + * in an object reference (see {@link JsonInclude} for further + * details on this distinction) * * @since 2.21 */ @@ -315,6 +335,11 @@ public static class Value /** * The equivalent to {@link Include#NON_DEFAULT} for specifying * inclusion of non-defaults for both values and content. + *

+ * This will specify the same setting for including a value both + * on Java object level as well as when contained + * in an object reference (see {@link JsonInclude} for further + * details on this distinction) * * @since 2.21 */ From 426a065707334aac87ec423063a4e14ffcee2000 Mon Sep 17 00:00:00 2001 From: Rune Flobakk Date: Sat, 6 Sep 2025 21:57:58 +0200 Subject: [PATCH 4/5] Rephrase to use "Constant" instead of "Value" When referring to the instances of JsonInclude.Value, to avoid too much overloading with "values" referring to values being serialized to JSON. See also discussion: https://github.com/FasterXML/jackson-annotations/pull/314#discussion_r2328334071 --- .../jackson/annotation/JsonInclude.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java b/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java index 4bf411e6..5011ec74 100644 --- a/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java +++ b/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java @@ -269,13 +269,13 @@ public static class Value private static final long serialVersionUID = 1L; /** - * Value that indicates that property is to be always included, + * Constant that indicates that property is to be always included, * independent of value of the property. *

* This will specify the same setting for including a value both * on Java object level as well as when contained * in an object reference (see {@link JsonInclude} for further - * details on this distinction) + * details on this distinction). * * @since 2.21 */ @@ -283,13 +283,13 @@ public static class Value .construct(Include.ALWAYS, Include.ALWAYS); /** - * Value that indicates that only properties with non-null + * Constant that indicates that only properties with non-null * values are to be included. *

* This will specify the same setting for including a value both * on Java object level as well as when contained * in an object reference (see {@link JsonInclude} for further - * details on this distinction) + * details on this distinction). * * @since 2.21 */ @@ -297,7 +297,7 @@ public static class Value .construct(Include.NON_NULL, Include.NON_NULL); /** - * Value that indicates that properties are included unless their value + * Constant that indicates that properties are included unless their value * is: *

    *
  • null
  • @@ -310,7 +310,7 @@ public static class Value * This will specify the same setting for including a value both * on Java object level as well as when contained * in an object reference (see {@link JsonInclude} for further - * details on this distinction) + * details on this distinction). * * @since 2.21 */ @@ -318,14 +318,14 @@ public static class Value .construct(Include.NON_ABSENT, Include.NON_ABSENT); /** - * Value that indicates that only properties with null value, + * Constant that indicates that only properties with null value, * or what is considered empty, are not to be included. * See {@link Include#NON_EMPTY} for further details. *

    * This will specify the same setting for including a value both * on Java object level as well as when contained * in an object reference (see {@link JsonInclude} for further - * details on this distinction) + * details on this distinction). * * @since 2.21 */ @@ -339,7 +339,7 @@ public static class Value * This will specify the same setting for including a value both * on Java object level as well as when contained * in an object reference (see {@link JsonInclude} for further - * details on this distinction) + * details on this distinction). * * @since 2.21 */ From fc3365942c56b08b55715cc127624a786b644095 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Mon, 8 Sep 2025 17:58:16 -0700 Subject: [PATCH 5/5] Add release notes --- release-notes/VERSION-2.x | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 4175c585..89d50f85 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -16,7 +16,8 @@ NOTE: Jackson 3.x components rely on 2.x annotations; there are no separate 2.21 (not yet released) -No changes since 2.20 +#314: Add `JsonInclude.Value` convenience constants + (contributed by @runeflobakk) 2.20 (28-Aug-2025)