Skip to content

Honor @JsonIgnoreType for Creator properties - #6284

Open
aysha-afrah26 wants to merge 2 commits into
FasterXML:3.xfrom
aysha-afrah26:ignoretype-creator-props
Open

aysha-afrah26 wants to merge 2 commits into
FasterXML:3.xfrom
aysha-afrah26:ignoretype-creator-props

Conversation

@aysha-afrah26

Copy link
Copy Markdown
Contributor

@JsonIgnoreType (and setIsIgnoredType(true) config overrides) is applied in BeanDeserializerFactory.filterBeanProps(), but only to properties without a constructor parameter, so a property-based @JsonCreator parameter or a Record component of an ignored type still binds from input. With record Account(String name, Credentials creds) and Credentials marked @JsonIgnoreType, serialization drops creds as expected, yet {"name":"bob","creds":{"role":"admin"}} reads back with a populated Credentials, while the same type as a field, setter or builder property is skipped. So request JSON can populate a type the application declared off-limits whenever that type reaches the object through a Creator. I ran into it while comparing ignoral handling between Creator and setter-based properties. Dropping the constructor-parameter exemption routes these properties through builder.addIgnorable(), the same way explicitly ignored names already are, so BeanDeserializerBase.resolve() marks the Creator property ignorable and the constructor gets null instead of the input value. The new tests in IgnoredTypesTest (Creator, Record, config override) fail on 3.1 without the change, and full ./mvnw verify passes with it. Same code is on 3.2, 3.x and 2.x; targeting 3.1 as the LTS line, and since this touches the same block of filterBeanProps() as #6202, whichever lands second needs a trivial rebase.

Type-based ignoral was skipped for properties with a constructor parameter, so a property-based Creator parameter or Record component of an ignored type still bound from input. Register such names as ignorable like explicitly ignored ones, so the Creator property is marked ignorable during resolve().
@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 82.51% 📈 +0.000%
Branches branches 76.39% 📈 +0.010%

Coverage data generated from JaCoCo test results

@gitar-bot

gitar-bot Bot commented Oct 16, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 closed / 1 findings

🟡 Medium risk

Honors @JsonIgnoreType and setIsIgnoredType(true) overrides for property-based @JsonCreator parameters and Record components by routing them through builder.addIgnorable(), so ignored types no longer bind from input. Resolved the open concern that ignored Creator params would now fail with FAIL_ON_MISSING_CREATOR_PROPERTIES. No open issues found.

✅ 1 closed
✅ Edge Case: Ignored-type Creator params now fail with FAIL_ON_MISSING_CREATOR_PROPERTIES

📄 src/main/java/tools/jackson/databind/deser/BeanDeserializerFactory.java:781-790 📄 src/test/java/tools/jackson/databind/ser/filter/IgnoredTypesTest.java:178-192
Before this change, a Creator/Record parameter of a @JsonIgnoreType type was always bound. Now it is added via builder.addIgnorable() and marked ignorable in BeanDeserializerBase.resolve(), so PropertyBasedCreator drops it from _propertyLookup and it never gets assigned. PropertyValueBuffer.getParameters() then calls _findMissing() for it, and that method throws Missing creator property 'creds' when DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES is on. It also throws Missing required creator property when the parameter has @JsonProperty(required = true).

So with that feature enabled, record Account(String name, Credentials creds) now fails on every input, even when creds is in the JSON. Before this change the same input worked. Explicitly @JsonIgnored Creator params already behave this way, but this PR brings the failure to every Record or Creator that uses an ignored type. A fix is to skip the missing/required checks in _findMissing() for prop.isIgnorable() and go straight to the absent/null value. Either way, add a test that enables FAIL_ON_MISSING_CREATOR_PROPERTIES.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 82.50% 📉 -0.010%
Branches branches 76.36% 📉 -0.020%

Coverage data generated from JaCoCo test results

This branch has not been deployed

No deployments
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