GH-398 - Fix Association deserialization with implicit property-based creators#399
Open
ogawa-takeshi wants to merge 1 commit into
Open
Conversation
…erty-based creators. When Jackson 3 auto-detects a public parameterized constructor as an implicit property-based creator, it uses the constructor parameter types for deserialization. This causes failures when the constructor parameter type (e.g. an AggregateRoot) differs from the bean property type (Association). The fix detects this type mismatch in updateBuilder() and: 1. Disables the implicit property-based creator so Jackson falls back to the default (no-arg) constructor. 2. Replaces the wrongly-typed property in the builder with one derived from the bean's setter or field, which has the correct Association type. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #398.
When Jackson 3 auto-detects a public parameterized constructor as an implicit property-based creator, it uses the constructor parameter types for deserialization. This causes failures when the constructor parameter type (e.g. an
AggregateRoot) differs from the bean property type (Association).This commonly occurs with jMolecules ByteBuddy plugin, which adds public no-arg constructors to entity classes for JPA. Jackson 3 then sees both the no-arg constructor and the original public parameterized constructor, selecting the latter as an implicit creator.
Changes
SingleValueWrappingTypeDeserializerModifier: AddedupdateBuilder()override that detects when a property-based creator parameter type mismatches anAssociation-typed bean property, and:ValueInstantiatorto returnfalseforcanCreateFromObjectWith())Associationtype)JMoleculesModuleUnitTests: Added test reproducing the issue with a class that has a public constructor whose parameter name matches anAssociation-typed field.Test plan
deserializesAssociationWithImplicitCreatorpasses