When deserializing MyEntity
(which is an interface) I either have
the following input:
{ "id": 123 }
in which case I would like to deserialize it into a
new MyEntityRef(123)
or I have the following input:
{ "id": 123, "message": "Hello world", "otherEntity": { "field": "value", ... } }
in which case I would like to deserialize it as
new MyEntityImpl(123, "Hello world", otherEntity);
where
otherEntity
is deserialized the same way as if it was found outside the context ofMyEntity
.
I've figured out how to register my own custom deserializer through a SimpleModule
but I don't know how to
- Choose a custom deserializer based on the presense of some field (such as
message
above). - Fallback on the "default" serializer for certain fields (such as
otherEntity
above).