Fix #6190: honor explicit @JsonView on standard Throwable properties - #6192
Conversation
…` properties `ThrowableDeserializer` exempts standard `Throwable` properties from view filtering, because without views they default out of every view under `MapperFeature.DEFAULT_VIEW_INCLUSION` disabled. However, exempting them based on property identity in `ThrowableDeserializer` unconditionally bypassed explicit `@JsonView` annotations placed on those properties (e.g. overriding `setStackTrace` or `initCause` to restrict them to an internal view). Fix where views are assigned without adding state to `SettableBeanProperty`: - In `BeanDeserializerFactory.buildThrowableDeserializer()`, do not force default views (`NO_VIEWS`) onto standard `Throwable` properties (`stackTrace`, `cause`) that lack explicit `@JsonView` annotations, allowing them to remain visible under any view. - When an explicit `@JsonView` is configured on `stackTrace` or `cause` (including via `initCause` or `getCause`), configure its explicit view matcher. - Support `findViews()` on `SimpleBeanPropertyDefinition`. - In `ThrowableDeserializer.deserializeFromObject()`, remove the identity-based exemption bypass so standard view visibility checks apply uniformly.
5e022e6 to
24d475e
Compare
|
Looks promising. Before I can merge, just need to make sure you we have a CLA from you @adityabagla7. If you haven't sent one, it's from https://github.com/FasterXML/jackson/blob/main/CLA-jackson-2026.pdf and is usually easiest to do by printing it, filling & signing, scan/photo, email to Looking forward to merging this! |
|
Thanks @cowtowncoder! I have just emailed the signed CLA to cla@fasterxml.com. Looking forward to having this merged! |
|
@adityabagla7 Thank you for sending CLA super quickly! I hope to get the review complete and merge soon -- hopefully tomorrow. |
JooHyukKim
left a comment
There was a problem hiding this comment.
Others may think differenlty, but the tests volume is sufficient for dedicated test class, WDYT?
| if (views == null) { | ||
| for (BeanPropertyDefinition pd : beanDesc.findProperties()) { | ||
| if ("cause".equals(pd.getInternalName())) { | ||
| views = pd.findViews(); |
There was a problem hiding this comment.
null check needed right?
Should only assign to views if not null and also break only if non-null views found.
There was a problem hiding this comment.
Good catch! Updated so it only assigns and breaks when non-null views are found.
… cause views lookup - Move explicit @JSONVIEW tests into dedicated ThrowableViewExplicit6190Test - In BeanDeserializerFactory, only assign and break when non-null views are found on cause property definition
|
Agreed @JooHyukKim! I have moved the explicit view tests into a dedicated test class |
Code Review ✅ Approved 3 resolved / 3 findingsHonors explicit ✅ 3 resolved✅ Quality: Javadoc for _shouldSkipNullValue detached, now docs _visibleInView
✅ Edge Case: message/suppressed view-skip ignores FAIL_ON_UNEXPECTED_VIEW_PROPERTIES
✅ Edge Case: Explicit view on message/suppressed ignored if DEFAULT_VIEW_INCLUSION on
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 #6190.
Problem
#6174 made
ThrowableDeserializerhonor@JsonView, and exempted the standardThrowableproperties from view filtering via_isStandardThrowableProperty(). That exemption was needed because un-annotated properties default to exclusion (NO_VIEWS) underMapperFeature.DEFAULT_VIEW_INCLUSIONdisabled.However, because the exemption was applied at deserialize time based on the property's name alone, an explicit
@JsonViewplaced on one of those properties (e.g. by overridingsetStackTraceorinitCauseto restrict it to an internal view) was unconditionally bypassed.Solution
Instead of adding state to
SettableBeanPropertyor bypassing checks at deserialize time, fix the view assignments at construction time where the distinction between explicit and defaulted views is known:BeanDeserializerFactory.buildThrowableDeserializer():Throwableproperties (stackTrace,cause) that have no explicit@JsonViewannotations (propDef.findViews() == null), do not force default views (NO_VIEWS) onto them (setViews(null)). This leaves_viewMatcher == null, so they remain visible under any active view by default without requiring an exemption check during deserialization.Throwableproperties that do have explicit@JsonViewannotations (including oninitCauseorgetCause), configure their explicit views onto the property.SimpleBeanPropertyDefinition, implementedfindViews()delegating to_memberso views oninitCauseare recognized.ThrowableDeserializer.deserializeFromObject(), remove the identity-based exemption bypass: standard view visibility (!prop.visibleInView(activeView)) now works uniformly for all properties, including standardThrowableproperties.SettableBeanPropertyremains completely unchanged (no new state/fields added).ThrowableViewDeserializationBypassTest:@JsonViewonstackTraceunder active view, excluded view, and no view@JsonViewoncauseunder active view and excluded viewDeserializationFeature.FAIL_ON_UNEXPECTED_VIEW_PROPERTIESPropertyNamingStrategy(e.g., snake_case)