Skip to content

fix(java-dsl): When serialising error classes that have their own @JsonIgnoreProperties, still strip the throwable properties - #1473

Merged
TimothyJones merged 2 commits into
case-contract-testing:mainfrom
JamesBurnsCanva:20261002-error-internals-mixin-override
Oct 6, 2026
Merged

TimothyJones merged 2 commits into
case-contract-testing:mainfrom
JamesBurnsCanva:20261002-error-internals-mixin-override

Conversation

@JamesBurnsCanva

Copy link
Copy Markdown
Contributor

Issue: #1467

Problem

errorInternalsMapper() strips the standard Throwable properties via a mixin registered on Throwable.class.
Jackson resolves @JsonIgnoreProperties by most-specific-wins rather than by merging ignored sets, so a class-level annotation on the exception overrides the inherited mixin entirely.
This results in the ignored Throwable properties being serialised again.

Fix

Replace the mixin with a JacksonAnnotationIntrospector which, for any Throwable, ignores the union of the class-specific @JsonIgnoreProperties and our specified Throwable properties when serialising.

Notes

  1. This is a breaking change. If in the brief window between errorInternals getting support and this fix occurring anybody has hit this exact edge case and started matching on these properties, an upgrade will cause them to fail to verify.
  2. This can't be tested the same way everything else in the DSL is tested. The rest of the Java DSL tests are done by checking end-to-end behaviour with contracts. This test would need to fail when properties are present, but pass when they are absent, which can't be expressed as contracts. Instead, I used a unit test. If you don't like this precedent, feel free to delete the new test class.

…internals, so that an exception's own class-level @JsonIgnoreProperties can no longer reintroduce its stack trace - Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…s, including that an exception's own ignored properties are added to them rather than replaced - Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@TimothyJones

Copy link
Copy Markdown
Member

Nice one.

For next time, you call out the breaking change in the commit message - the commit guidelines are in the contributing doc here: https://github.com/case-contract-testing/contract-case/blob/main/CONTRIBUTING.md

@TimothyJones TimothyJones changed the title fix(java-dsl): Force removal of Throwable properties when serialising errors fix(java-dsl)!: Force removal of Throwable properties when serialising errors Oct 6, 2026
@TimothyJones TimothyJones changed the title fix(java-dsl)!: Force removal of Throwable properties when serialising errors fix(java-dsl): When serialising error classes that have their own @JsonIgnoreProperties, still strip the throwable properties Oct 6, 2026
@TimothyJones
TimothyJones merged commit a939dca into case-contract-testing:main Oct 6, 2026
15 checks passed
@TimothyJones

Copy link
Copy Markdown
Member

Merged as a non-breaking change, following the guideline of fixes to unexpected behaviour bugs that are either documented or outside what a user would normally expect aren't breaking changes (also I'm pretty sure you're the only one using the error serialisation feature).

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