0

Is it possible to convert JSON to Java bean interface that has interfaces as attributes? I have one implementation of every interface and these can be directly mapped to interfaces.

Example:

public interface MyMainClass {

    public MyInterfaceClass1 getMyInterfaceClass1();

}
newbie
  • 24,286
  • 80
  • 201
  • 301

1 Answers1

1
  1. It is impossible to say whether there are other implementations of the interface: classloaders are free to create new classes on demand.
  2. The answer is, use @JsonDeserialize(as=YourImpl.class), see Jackson JSON, Immutable Classes, and Interfaces
  3. My bad, for GSON it's .registerTypeAdapter(Node.class, new NodeDeserializer()) and Deserializing an abstract class in Gson
Community
  • 1
  • 1
alf
  • 8,377
  • 24
  • 45