Skip to content

Fix #6043: honor FAIL_ON_UNKNOWN_PROPERTIES for creator-based POJOs-as-Array - #6047

Merged
cowtowncoder merged 3 commits into
FasterXML:3.2from
seonwooj0810:fix/issue-6043-beanasarray-creator-failonunknown
Jun 24, 2026
Merged

Fix #6043: honor FAIL_ON_UNKNOWN_PROPERTIES for creator-based POJOs-as-Array#6047
cowtowncoder merged 3 commits into
FasterXML:3.2from
seonwooj0810:fix/issue-6043-beanasarray-creator-failonunknown

Conversation

@seonwooj0810

Copy link
Copy Markdown
Contributor

Fixes #6043

Root cause

For POJOs serialized as JSON Arrays (@JsonFormat(shape = ARRAY)), the creator-based deserialization path BeanAsArrayDeserializer._deserializeUsingPropertyBased loops over array elements and, once it runs past the property count, hits the prop == null branch where it simply skipChildren() and continues. Unlike the non-creator paths (deserialize/_deserializeNonVanilla), it never consults FAIL_ON_UNKNOWN_PROPERTIES. As a result, extra array elements are silently ignored for creator-based types such as records, even when the feature is enabled.

Change

Add the same FAIL_ON_UNKNOWN_PROPERTIES guard already used on the non-creator paths to the prop == null (extra-element) branch of the creator path, reporting reportWrongTokenException with the existing "Unexpected JSON values; expected at most N properties" message. Behavior is unchanged when the feature is disabled or @JsonIgnoreProperties(ignoreUnknown = true) applies.

Test evidence

Added POJOAsArrayTest.testCreatorUnknownExtraProp using the issue's reproduction (a record XYZParams(int x, int y, int z) annotated @JsonFormat(shape = ARRAY) reading [1, 2, 3, 4]). It fails before the fix (no exception thrown — "should not pass with extra element") and passes after, and also asserts the value still deserializes correctly when the feature is disabled. Full POJOAsArrayTest (27 tests) passes.

Verification done: ran ./mvnw test -Dtest=POJOAsArrayTest (27/27 pass with fix); reverted the source change and confirmed the new test fails (assertion "should not pass with extra element"), then restored.

@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 81.69% 📈 +0.010%
Branches branches 75.14% 📈 +0.020%

Coverage data generated from JaCoCo test results

@cowtowncoder

Copy link
Copy Markdown
Member

Makes sense, thank you for submitting this, @seonwooj0810 !

Two quick things:

  1. Seems like a safe enough to backport: could you change/re-create to be against 3.2 branch so it could go in 3.2.1 patch?
  2. I think this is your first contribution -- if so, we'd need CLA, from https://github.com/FasterXML/jackson/blob/main/CLA-jackson-2026.pdf. It only needs to be sent once (good for all future PRs): usual way is to print, fill & sign, email to cla at fasterxml dot com.

@cowtowncoder cowtowncoder added the cla-needed PR looks good (although may also require code review), but CLA needed from submitter label Jun 22, 2026
@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 81.69% 📈 +0.010%
Branches branches 75.13% 📈 +0.000%

Coverage data generated from JaCoCo test results

seonwooj0810 and others added 2 commits June 22, 2026 21:14
…d POJOs-as-Array

BeanAsArrayDeserializer._deserializeUsingPropertyBased silently skipped JSON
Array elements past the property count, ignoring FAIL_ON_UNKNOWN_PROPERTIES for
creator-based types such as records. Mirror the check already present on the
non-creator deserialization paths.
@seonwooj0810
seonwooj0810 force-pushed the fix/issue-6043-beanasarray-creator-failonunknown branch from f903ba9 to b7bfd2d Compare June 22, 2026 12:18
@seonwooj0810
seonwooj0810 changed the base branch from 3.x to 3.2 June 22, 2026 12:18
@seonwooj0810

Copy link
Copy Markdown
Contributor Author

Thanks @cowtowncoder!

  1. Done — I've re-targeted this PR to the 3.2 branch. The fix is now rebased on top of 3.2 (your Add tighter check to avoid potential false failures commit is preserved on top), and POJOAsArrayTest passes locally (27/27). The PR shows a clean 2-file diff against 3.2 and reports as mergeable.
  2. Yes, this is my first contribution here — I'll print, fill, sign and email the CLA to cla@fasterxml.com.

@cowtowncoder

cowtowncoder commented Jun 22, 2026 via email

Copy link
Copy Markdown
Member

@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 81.69% 📈 +0.010%
Branches branches 75.14% 📈 +0.010%

Coverage data generated from JaCoCo test results

@seonwooj0810

Copy link
Copy Markdown
Contributor Author

Quick correction on the CLA front, @cowtowncoder: I actually already have a signed Jackson CLA on file — I had submitted it previously (emailed to cla@fasterxml.com) rather than this being a brand-new one, so there shouldn't be anything outstanding on that side. Apologies for the mixed signal in my earlier reply. Happy to re-send a copy if it's easier to confirm on your end.

@cowtowncoder

Copy link
Copy Markdown
Member

No need -- I'll double-check I can find it when I get home.

@cowtowncoder

cowtowncoder commented Jun 24, 2026

Copy link
Copy Markdown
Member

Found it! Reason I was confused was Github comment on it being the first contribution -- but this is because your earlier PR was for jackson-core, not databind.

@cowtowncoder cowtowncoder added cla-received PR already covered by CLA (optional label) and removed cla-needed PR looks good (although may also require code review), but CLA needed from submitter labels Jun 24, 2026
@cowtowncoder cowtowncoder modified the milestones: 2.13.2.1, 3.2.1 Jun 24, 2026
@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 81.69% 📈 +0.010%
Branches branches 75.15% 📈 +0.030%

Coverage data generated from JaCoCo test results

@cowtowncoder
cowtowncoder merged commit b21963c into FasterXML:3.2 Jun 24, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-received PR already covered by CLA (optional label)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FAIL_ON_UNKNOWN_PROPERTIES has no effect with JsonFormat.Shape.ARRAY when using creator-based instantiation (such as record)

2 participants