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

defining different JsonTypeInfo annotations in both the superclass and the subtype results in ambiguity #4668

Open
1 task done
wesleyking0 opened this issue Aug 17, 2024 · 3 comments

Comments

@wesleyking0
Copy link

wesleyking0 commented Aug 17, 2024

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

There is my case:

@JsonTypeInfo(use = Id.NAME, property = "animalType")
@JsonSubTypes({
    @Type(value = Humanity.class, name = "mammal")
})
class Animal {
    String animalType;
}

@JsonTypeInfo(use = Id.NAME, property = "mammalType")
@JsonSubTypes({
    @Type(value = Humanity.class, name = "humanity")
})
class Mammal extends Animal {
    String mammalType;
}

class Humanity extends Mammal {
}

I have a JSON string:

{
    "animalType": "mammal",
    "mammalType": "humanity"
}

I wish to return an instance of the Humanity when I parse the JSON string, but with the version 2.17.1 i am using, I am getting an instance of Mammal returned instead.

Version Information

2.17.1

Reproduction

Expected behavior

No response

Additional context

No response

@wesleyking0 wesleyking0 added the to-evaluate Issue that has been received but not yet evaluated label Aug 17, 2024
@cowtowncoder
Copy link
Member

cowtowncoder commented Aug 20, 2024

Subtypes should not try to override @JsonTypeInfo: this is not supported functionality. And as such, results of trying to do that are undefined.

So... I don't think there's necessarily bug to fix. Although example is missing piece of code used for writing/reading json.

@cowtowncoder cowtowncoder removed the to-evaluate Issue that has been received but not yet evaluated label Aug 20, 2024
@wesleyking0
Copy link
Author

Unn... I think it is a new feature. I don't known how much requirement the feature will have, but it is a good enhance to the Jackson.

@cowtowncoder
Copy link
Member

@wesleyking0 I do not think this is something that should be done, ever. I am ok leaving this open, but currently disagree with the idea fundamentally.

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

No branches or pull requests

2 participants