Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
78 changes: 78 additions & 0 deletions src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
* This will specify the same setting for including a value both
* on <b>Java object level</b> as well as when <b>contained</b>
* in an object reference (see {@link JsonInclude} for further
* details on this distinction).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually makes sense & looks good. Thank you for doing this.

*
* @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.
* <p>
* This will specify the same setting for including a value both
* on <b>Java object level</b> as well as when <b>contained</b>
* 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:
* <ul>
* <li>null</li>
* <li>"absent" value of a referential type (like Java 8 `Optional`, or
* {@link java.util.concurrent.atomic.AtomicReference}); that is, something
* that would not deference to a non-null value.
* </ul>
* This option is mostly used to work with "Optional"s (Java 8, Guava).
* <p>
* This will specify the same setting for including a value both
* on <b>Java object level</b> as well as when <b>contained</b>
* 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.
* <p>
* This will specify the same setting for including a value both
* on <b>Java object level</b> as well as when <b>contained</b>
* 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.
* <p>
* This will specify the same setting for including a value both
* on <b>Java object level</b> as well as when <b>contained</b>
* 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);

Expand Down