Hi everyone,
Some of my classes have associations with other classes. Generally, these association attributes are typed as interfaces.
class PersonImpl implements Person {
private String name;
private Country country; // Country is actually an interface
...
}
Using Genson, I try to deserialize a JSON string into a pojo of type Person.
Object entity = factory.build(Person.class); // Creates an instance of Person
Genson genson = new GensonBuilder().create();
genson.deserializeInto(str, entity);
However when Genson tries to deserialize the country property it fails finding a constructor as it doesn't know the implementation of the interface.
I see two different approaches to deal with this problem:
- Genson should use my factory to build instances.
- Genson should us a sort of "type adapter" which returns the implementation class of any interface.
In your opinion, which of the two approaches would suit my needs and how would you implement it in Genson ?
Thanks a lot in advance for your help!!