Throw JsonParseException when the type read does not derive from baseClass
@@ -113,6 +113,10 @@ public R read(JsonReader in) throws IOException {
valueClass = baseClass;
}
+ if (!baseClass.isAssignableFrom(valueClass)) {
+ throw new JsonParseException(valueClass.getName() + " does not derive from " + baseClass.getName());
+ }
+
TypeToken<?> valueType = TypeToken.get(valueClass);
TypeAdapter<R> delegate = (TypeAdapter<R>)
gson.getDelegateAdapter(PolymorphicTypeAdapterFactory.this, valueType);
