Skip to content

@JsonAlias not respected by polymorphic deduction #4327

Description

@k-wall

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    polymorphic-deductionIssues related to "Id.DEDUCTION" mode of `@JsonTypeInfo`

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions