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) diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java b/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java index 0704460b..5011ec74 100644 --- a/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java +++ b/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java @@ -268,6 +268,84 @@ public static class Value { private static final long serialVersionUID = 1L; + /** + * 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). + * + * @since 2.21 + */ + public final static Value ALL_ALWAYS = Value + .construct(Include.ALWAYS, Include.ALWAYS); + + /** + * 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). + * + * @since 2.21 + */ + public final static Value ALL_NON_NULL = Value + .construct(Include.NON_NULL, Include.NON_NULL); + + /** + * Constant that indicates that properties are included unless their value + * is: + *
+ * 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 + */ + public final static Value ALL_NON_ABSENT = Value + .construct(Include.NON_ABSENT, Include.NON_ABSENT); + + /** + * 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). + * + * @since 2.21 + */ + 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. + *
+ * 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 + */ + 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);