Given a JSON structure with this shape:
{ "type": "a"
"inner": { ... } }
And the following java classes:
class Outer
{
private final String type;
private final Inner inner;
public Outer(String type, Inner inner)
{
this.type = type;
this.inner = inner;
}
}
interface Inner {}
class Inner1 implements Inner { ... }
class Inner2 implements Inner { ... }
How do I get Jackson to deserialize the structure into Outer
, such that if type == "a"
, inner
is created from Inner1
, if it's "b"
it gets created from Inner2
, etc.?
BTW, I need to be able to handle the case where possible implementations of Inner
are not known at compile time.
I think following would do it:
but then registration of subtypes is another question.