This class imposes strict requirements on its use:
*
*
- *
Base types may be classes or interfaces. You may not use {@code Object.class} as a base
- * type.
+ *
Base types may be classes or interfaces.
*
Subtypes must encode as JSON objects.
*
Type information must be in the encoded object. Each message must have a type label like
* {@code hand_type} whose value is a string like {@code blackjack} that identifies which type
@@ -125,10 +124,6 @@ public final class PolymorphicJsonAdapterFactory implements JsonAdapter.Facto
public static PolymorphicJsonAdapterFactory of(Class baseType, String labelKey) {
if (baseType == null) throw new NullPointerException("baseType == null");
if (labelKey == null) throw new NullPointerException("labelKey == null");
- if (baseType == Object.class) {
- throw new IllegalArgumentException(
- "The base type must not be Object. Consider using a marker interface.");
- }
return new PolymorphicJsonAdapterFactory<>(
baseType, labelKey, Collections.emptyList(), Collections.emptyList());
}
@@ -162,9 +157,7 @@ public final class PolymorphicJsonAdapterFactory implements JsonAdapter.Facto
jsonAdapters.add(moshi.adapter(subtypes.get(i)));
}
- JsonAdapter