Is there any way to put a field inside a document's model as interface? Example:
public class Foo {
private String id;
private Bar bar;
}
Where Bar is an interface with multiple implementations. Inside Bar there is a method signature String getType() which it tells me which implementation I can use in order to map the data from the DB.
I've tried different solutions (@ReadingConverter/@WiritingConverter, @JsonSerialize/@JsonDeserialize) with no results. Every time I get
Failed to instantiate [Bar]: Specified class is an interface
Any help? Thank you!
It looks like you want polymorphic serialisation/deserialisation. You should look at the Jackson docs for that: http://www.baeldung.com/jackson-advanced-annotations
In short, you'll want to do something like this, where a
@JsonTypeIdResolverannotation is used to define a custom type resolver: