Gson deserialize json. java.lang.RuntimeException: Failed to invoke public com.derp.procedure.model.SkeletonElement() with no args] with root cause

com.derp.procedure.model.SkeletonElement is an abstract class. Make this class concrete deleting the abstract modifier.


If you want to keep class abstract, you need to write custom deserialization using Gson's JsonDeserializer and register it as type adapter. So let's say you have abstract class A and derived class B (B extends A):

JsonDeserializer<A> deserializer = ...; 
gsonBuilder.registerTypeAdapter(A.class, deserializer);

Now inside JsonDeserializer you have to specify that A should deserialize into B:

return context.deserialize(json, B.class);

That makes more sense if you have multiple classes that derive from abstract class A. Let's say that both B and C derive from A. In that scenario you would need to handle deserialization for both of them (inside JsonDeserializer<A>):

if (json is of class B) {
  return context.deserialize(json, B.class);
}
if (json is of class C) {
  return context.deserialize(json, C.class);
}
...