Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
@pjfanning Since this is a new feature, let's target 3.x (3.3) instead of 3.1. |
@JsonView on @JsonAnySetter when deserializing@JsonView on @JsonAnySetter when deserializing
Views declared on an any-setter were ignored on deserialization, so values were passed to it regardless of the active view -- unlike regular properties, and unlike `@JsonAnyGetter` on serialization. Now, if the any-setter is not visible in the active view, the value is skipped (or, with `DeserializationFeature.FAIL_ON_UNEXPECTED_VIEW_PROPERTIES`, reported), same as for regular properties. Only an explicit `@JsonView` on the any-setter itself is considered; class-level default views are not applied, so un-annotated any-setters behave as before. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5f511b8 to
aeac960
Compare
… notes entry under FasterXML#6260 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Code Review ✅ Approved🔴 High risk · Enforcing active-view checks on any-setter input changes which fields can be populated, potentially dropping client-supplied data or rejecting requests. Honors an explicit VerificationRules No rules evaluated Functional validation Not enabledFor more verification details, comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
Fixes #6260.
Changes
SettableAnyPropertynow stores views (setViews(),visibleInView(),hasViews()), andwithValueDeserializer()carries them over.BeanDeserializerFactoryreads an explicit@JsonViewfrom the any-setter accessor. This works for methods, fields and creator parameters.BeanDeserializerBuilder._anyViews()enables view processing when the any-setter has views.BeanDeserializerBase._skipIfAnySetterNotInView(), called at every point where a value goes to the any-setter: the vanilla, creator, record-update, unwrapped and external-type-id paths,BuilderBasedDeserializer, andThrowableDeserializer. A hidden value is skipped. IfFAIL_ON_UNEXPECTED_VIEW_PROPERTIESis enabled, it is reported instead, the same way as for regular properties.Tradeoff
Only an explicit
@JsonViewon the any-setter counts. Class-level default views andDEFAULT_VIEW_INCLUSIONare not applied to it. That differs from regular properties and from@JsonAnyGetter. Applying them would mean that with 3.x defaults (DEFAULT_VIEW_INCLUSIONdisabled), an un-annotated any-setter stops receiving any values once a view is active. That seemed too big a behavior change for a patch release. If full symmetry is wanted, it could be done in 3.3.Tests
Added
AnySetterViewDeserializationTest, which covers method, field, creator-bean, record creator-parameter and builder any-setters, an un-annotated any-setter (behavior unchanged), andFAIL_ON_UNEXPECTED_VIEW_PROPERTIES. Without the fix, 6 of its 7 tests fail../mvnw verifypasses.🤖 Generated with Claude Code