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

Abstract class included as part of known type ids for error message when using JsonSubTypes #1919

Closed
Incara opened this issue Jan 30, 2018 · 3 comments
Milestone

Comments

@Incara
Copy link

Incara commented Jan 30, 2018

I have the below class definition:

public class SomeClass {

    private SomeType type;

    @JsonTypeInfo(
            visible = true,
            use = JsonTypeInfo.Id.NAME,
            include = JsonTypeInfo.As.EXTERNAL_PROPERTY,
            property = "type")
    @JsonSubTypes({
            @JsonSubTypes.Type(value = SubType1.class, name = "subType1"),
            @JsonSubTypes.Type(value = SubType2.class, name = "subType2"),
            @JsonSubTypes.Type(value = SubType3.class, name = "subType3")
    })
    private final SuperType superType; //SuperType is abstract

    //getters/setters
}

When attempting to deserialize, if I specify the wrong property, I receive the correct error stating:

Could not resolve type id 'string' into a subtype of [simple type, class SomeClass]: known type ids = [SuperType, subType1, subType2, subType3]

However, I want to know why my SuperType considered a known type id? Is there anyway to exclude it since it is an abstract class?

@cowtowncoder
Copy link
Member

@Incara At this point I think it gets included by default, since there are cases where base type is concrete and usable. It is even possible there might be actual value deserializer (at least in theory).
So I am not 100% sure if it'd be possible to remove it -- but at this point it will be included and there is nothing you can do to remove it from being considered valid (although attempt itself would fail unless there's static factory method producing some subtype).

@Incara
Copy link
Author

Incara commented Jan 30, 2018

Yes, it will always fail unfortunately, but the logic makes sense. I appreciate the quick response.

@Incara Incara closed this as completed Jan 30, 2018
@cowtowncoder
Copy link
Member

Actually, let's keep this open for now. I can see why this is sub-optimal... but most likely can only be tackled in 3.0.

@cowtowncoder cowtowncoder reopened this Jan 30, 2018
@cowtowncoder cowtowncoder added 2.12 and removed 3.x labels Apr 25, 2020
@cowtowncoder cowtowncoder added this to the 2.12.0 milestone May 6, 2020
@cowtowncoder cowtowncoder removed the 2.12 label May 6, 2020
@cowtowncoder cowtowncoder changed the title Abstract class included as part of known type ids when using JsonSubTypes Abstract class included as part of known type ids for error message when using JsonSubTypes May 6, 2020
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