Skip to content

Conversation

runeflobakk
Copy link
Contributor

See discussion here: FasterXML/jackson-databind#5294

This pull-request adds some constants to JsonInclude.Value equivalent to the enum values of JsonInclude.Include.

This e.g enables the following for configuring a JsonMapper:

var jsonMapper = JsonMapper.builder()
    .defaultPropertyInclusion(JsonInclude.Value.ALL_NON_NULL)
    .build();

I noticed a kind of established pattern in JsonInclude.Value to declare static final constants as protected, and use a static method to access it. If this pattern is also applicable for these constants, just let me know, and I will edit the pull-request accordingly!

Equivalent to the enum values of JsonInclude.Include.
See also discussion here:
FasterXML/jackson-databind#5294
@cowtowncoder
Copy link
Member

I think it's ok to just expose these particular constants without accessor.
Added couple of minor comments, but looks good overall.

One process thing: I'd need CLA:

https://github.com/FasterXML/jackson/blob/main/contributor-agreement.pdf

(unless you have sent one in the past, if so, LMK).

The usual way is to print, fill & sign, scan/photo, email to cla at fasterxml dot com. This only needs to be done once for any and all contributions.
Once I get it I can merge the PR (pending review/approval) etc.

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).
@cowtowncoder
Copy link
Member

NOTE: CLA received.

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:
FasterXML#314 (comment)
@cowtowncoder cowtowncoder changed the title Add JsonInclude.Value constants Add JsonInclude.Value convenience constants Sep 9, 2025
* 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.

Copy link
Member

@cowtowncoder cowtowncoder left a comment

Choose a reason for hiding this comment

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

LGTM

@cowtowncoder cowtowncoder merged commit 8e6d0e4 into FasterXML:2.x Sep 9, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants