I have the following class and it works as expected:
class TestClass
{
@Inject
public TestClass(
String type,
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", include = JsonTypeInfo.As.EXTERNAL_PROPERTY)
@JsonSubTypes(value = {
@JsonSubTypes.Type(value = String.class, name = "expression"),
@JsonSubTypes.Type(value = List.class, name = "simple")
})
Object value)
{
}
}
The problem is that I need to use an enum to map the values so I did the following:
class TestClass
{
@Inject
public TestClass(
String type,
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", include = JsonTypeInfo.As.EXTERNAL_PROPERTY)
@JsonSubTypes(value = {
@JsonSubTypes.Type(value = String.class, name = MyEnum.EXPRESSION),
@JsonSubTypes.Type(value = List.class, name = MyEnum.SIMPLE)
})
Object value)
{
}
}
It doesn't work because MyEnum is not a String and the annotation values must be constant so I can't dynamically may an enum. Ideally, I will parse the value of type
field into MyEnum
and will map the subtypes based on the value of the type.