Skip to content

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

@Incara

Description

@Incara

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions