Skip to content

ObjectMapper.registerSubtypes(NamedType...) doesn't allow to register the same POJO for two different type ids #2515

@mbaechler

Description

@mbaechler

registerSubtypes takes an array of NamedTypes:

    @Override    
    public void registerSubtypes(NamedType... types) {
        if (_registeredSubtypes == null) {
            _registeredSubtypes = new LinkedHashSet<NamedType>();
        }
        for (NamedType type : types) {
            _registeredSubtypes.add(type);
        }
    }

But unfortunately, if I want to register the same POJO for several types (let's say the JSONs only differ on their type field), it will only register the first one because they are added to a LinkedHashSet and NamedType doesn't include name field in equals/hashcode.

I don't even create a subtype of NamedType to override equals/hashcode because the class it final.

Would it make sense to care about NamedType.name field ?

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