Honor @JsonIgnoreProperties for Creator props on builder and external-type-id paths - #6146
Honor @JsonIgnoreProperties for Creator props on builder and external-type-id paths#6146aysha-afrah26 wants to merge 3 commits into
@JsonIgnoreProperties for Creator props on builder and external-type-id paths#6146Conversation
…-type-id paths
| {"child":{"secret":"leaked","first":"Bob","last":"Smith"}} | ||
| """, | ||
| UnwrappedBuilderWrapper.class); | ||
| assertEquals("Bob", result.child.name.first); |
There was a problem hiding this comment.
Minor/optional: Since this test exercises the @JsonUnwrapped path, would it also make sense to assert result.child.name.last == "Smith"? That would explicitly verify that skipping the ignored Creator property doesn't affect deserialization of the remaining unwrapped properties.
There was a problem hiding this comment.
Good idea, added the last assertion and pushed. Both unwrapped properties come through fine after the ignored Creator prop is skipped.
|
@aysha-afrah26 Could this be targeted at 3.1 instead? Or is fix only needed for 3.2? |
|
The fix as written really only fits 3.2+: on 3.1 the #4629 guard is still gated on |
Jackson checks the
@JsonIgnorePropertiesset before assigning a Creator property, since a type with a property-based@JsonCreatorresolves a validcreatorPropand so never falls through to the by-name ignore check later in the same loop. That guard reacheddeserializeUsingPropertyBasedanddeserializeUsingPropertyBasedWithUnwrapped, but it never reacheddeserializeUsingPropertyBasedWithExternalTypeId, andBuilderBasedDeserializercarries no copy of it at all. The effect is that ignoring a property works for a plain POJO or record and quietly stops working for the same type once it is built through a@JsonPOJOBuilder, or once it gains an@JsonTypeInfo(include = EXTERNAL_PROPERTY)property, so a value the application excluded from binding is read off the document and handed to the constructor. I noticed it while comparing a builder-backed type with the equivalent plain Creator type and getting different results for identical input. The fix adds the check the sibling loops already use, right after the existingisInjectionOnlytest, at the three loops that lack it. Reported separately as #6145, which has a runnable reproduction for each of the three; the new test fails on all three before this change and passes after, and the rest of the suite is unchanged. I left3.1alone on purpose, because its copy of the guard is deliberately limited to records, so applying this there would widen behavior instead of closing a gap.