I'm using Jackson to try and deserialize this data structure:
{
"type": "foo", // or "bar", "baz", etc
"name": "number 1",
"params": {
// parameters specific to type 'foo'
}
}
I know I could use a custom deserializer, but I'm wondering if this is possible to do using just the @JsonType*
family of annotations?
Right now I have my classes set up something like this:
public class TopLevelObject {
String type;
String name;
AbstractParams params;
}
public class FooParams extends AbstractParams {
String one;
String two;
}
public class BarParams extends AbstractParams {
String three;
String four;
}
abstract public class AbstractParams {
}
I can use @JsonTypeInfo
on the type
property if I move the property into the AbstractParams
class, but I can't seem to get the same result while keeping the type
property in the TopLevelObject
.
Any ideas?