I have a class hierarchy that looks as follows:
interface MyEntity {
...
}
class MyEntityRef {
String id;
...
}
class MyEntityImpl {
String id;
String name;
...
}
I would like to serialize instances of MyEntityRef
as a plain string:
"someEntityId"
and instances of MyEntityImpl
as a regular object:
{
id: "someEntityId",
name: "someName"
}
And then the other way around: When deserializing a MyEntity
I'd like it to be deserialized into a MyEntityRef
if the json is a plain string, and into a MyEntityImpl
if it's a regular json object.
In my actual code I have many types of entities (i.e. multiple X
/XRef
/XImpl
triples). In an attempt to avoid listing all of these, I've annotated the interfaces as follows:
@MyEntityAnnotation(ref=MyEntityRef.class, impl=MyEntityImpl.class)
interface MyEntity {
...
}
Extra points to whomever figures out a way to solve the serialization/deserialization described above for all entities based this annotation information.
What I've tried: Everything I can think of (SimpleDeserializers
/SimpleSerializers
, BeanDeserializerModifier
/BeanSerializerModifier
, TypeSerializer
/TypeDeserializer
)