Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@JsonAlias not respected by polymorphic deduction #4327

Closed
1 task done
k-wall opened this issue Jan 17, 2024 · 1 comment · Fixed by #4335
Closed
1 task done

@JsonAlias not respected by polymorphic deduction #4327

k-wall opened this issue Jan 17, 2024 · 1 comment · Fixed by #4335
Labels
2.17 Issues planned at earliest for 2.17 polymorphic-deduction Issues related to "Id.DEDUCTION" mode of `@JsonTypeInfo`
Milestone

Comments

@k-wall
Copy link

k-wall commented Jan 17, 2024

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

I'm trying use @JsonAlias on a class which is a member of a type hierarchy, and then expecting Jackson Databind to be able to use the alias to determine the type.

My class hierarchy is Deduction, annotated with its two concrete implementations:

@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
    @JsonSubTypes({
            @JsonSubTypes.Type(value = DeductionBean1.class),
            @JsonSubTypes.Type(value = DeductionBean2.class)
    })

where DeductionBean2 uses an alias.

    record DeductionBean2(@JsonAlias("Y") int y) implements Deduction {
    }

This fails like so when deserializing {'Y': 2 }

com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve subtype of [simple type, class com.fasterxml.jackson.databind.deser.PropertyAliasTest$Deduction]: Cannot deduce unique subtype of `com.fasterxml.jackson.databind.deser.PropertyAliasTest$Deduction` (2 candidates match)
 at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 9]

Version Information

2.17
master

Reproduction

I've added a test tools.jackson.databind.deser.PropertyAliasTest#testAliasWithPolymorphicDeduction that demonstrates the issue I face.

k-wall@8380c94

Expected behavior

Aliases to be respected by DEDUCTION.

Additional context

No response

@k-wall k-wall added the to-evaluate Issue that has been received but not yet evaluated label Jan 17, 2024
@k-wall k-wall changed the title @JsonAlias does not work with polymorphic deduction. @JsonAlias not respected by polymorphic deduction. Jan 17, 2024
@cowtowncoder cowtowncoder added polymorphic-deduction Issues related to "Id.DEDUCTION" mode of `@JsonTypeInfo` 2.17 Issues planned at earliest for 2.17 labels Jan 17, 2024
@cowtowncoder cowtowncoder changed the title @JsonAlias not respected by polymorphic deduction. @JsonAlias not respected by polymorphic deduction Jan 24, 2024
@cowtowncoder cowtowncoder removed the to-evaluate Issue that has been received but not yet evaluated label Jan 24, 2024
@cowtowncoder cowtowncoder added this to the 2.17.0 milestone Jan 24, 2024
@k-wall
Copy link
Author

k-wall commented Jan 25, 2024

thank you @JooHyukKim

k-wall added a commit to k-wall/kroxylicious that referenced this issue Mar 19, 2024
With the inclusion of FasterXML/jackson-databind#4327
in the new Jackson release, the deprecated class can be replaced with a JsonAlias annotation.

Signed-off-by: kwall <kwall@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.17 Issues planned at earliest for 2.17 polymorphic-deduction Issues related to "Id.DEDUCTION" mode of `@JsonTypeInfo`
Projects
None yet
2 participants