Skip to content

GH-398 - Fix Association deserialization with implicit property-based creators#399

Open
ogawa-takeshi wants to merge 1 commit into
xmolecules:mainfrom
ogawa-takeshi:fix/gh-398-association-implicit-creator
Open

GH-398 - Fix Association deserialization with implicit property-based creators#399
ogawa-takeshi wants to merge 1 commit into
xmolecules:mainfrom
ogawa-takeshi:fix/gh-398-association-implicit-creator

Conversation

@ogawa-takeshi
Copy link
Copy Markdown

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: Added updateBuilder() override that detects when a property-based creator parameter type mismatches an Association-typed bean property, and:

    1. Disables the implicit property-based creator (wraps ValueInstantiator to return false for canCreateFromObjectWith())
    2. Replaces the wrongly-typed property in the builder with one derived from the setter or field (which has the correct Association type)
  • JMoleculesModuleUnitTests: Added test reproducing the issue with a class that has a public constructor whose parameter name matches an Association-typed field.

Test plan

  • New test deserializesAssociationWithImplicitCreator passes
  • All existing tests pass (9 tests, 0 failures)

…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>
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.

AssociationDeserializer not applied when Jackson 3 selects implicit property-based creator

1 participant