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

Support that multiple keys are mapped to the same class via @JsonSubTypes.Type #115

Open
LennartH opened this issue Jun 11, 2017 · 0 comments

Comments

@LennartH
Copy link

The following annotation example would result in an error that the type for Simple2 couldn't be found.

@JsonTypeInfo(use = Id.NAME, include = As.PROPERTY, property = "type", visible = true)
@JsonSubTypes({
    @JsonSubTypes.Type(value=ComplexImplementation1.class,name="Complex1"),
    @JsonSubTypes.Type(value=ComplexImplementation2.class,name="Complex2"),
    @JsonSubTypes.Type(value=SimpleImplementation.class,name="Simple1"),
    @JsonSubTypes.Type(value=SimpleImplementation.class,name="Simple2")
})
public interface Interface {
    enum Type {Complex1, Complex2, Simple1, Simple2}
    Type getType();
    ...
}

I think the problem is the way the concrete TypeDeserializationInfo is generated. The resulting method would look like this, ignoring the second type key for SimpleImplementation:

@Override
protected TypeDeserializationInfo<Interface> initTypeInfo() {
    return new TypeDeserializationInfo(JsonTypeInfo.As.PROPERTY, "type")
		.addTypeInfo(ComplexImplementation1.class, "Complex1")
		.addTypeInfo(ComplexImplementation2.class, "Complex2")
		.addTypeInfo(SimpleImplementation.class, "Simple1");
}

Could it be, that the generator uses the concrete implementations of Interface as loop condition and breaks after every implementation was mapped to a key?

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

No branches or pull requests

2 participants