From 47b28d99a17d492b37fcdd0fc41290419a010a0f Mon Sep 17 00:00:00 2001 From: Lyubomyr Shaydariv Date: Tue, 29 Oct 2019 01:11:15 +0200 Subject: [PATCH] The JavaDoc is now more accurate about the type adapter serialization and deserialization (#1441) --- .../gson/typeadapters/RuntimeTypeAdapterFactory.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/extras/src/main/java/com/google/gson/typeadapters/RuntimeTypeAdapterFactory.java b/extras/src/main/java/com/google/gson/typeadapters/RuntimeTypeAdapterFactory.java index 47e7f515..c496491a 100644 --- a/extras/src/main/java/com/google/gson/typeadapters/RuntimeTypeAdapterFactory.java +++ b/extras/src/main/java/com/google/gson/typeadapters/RuntimeTypeAdapterFactory.java @@ -120,6 +120,18 @@ import com.google.gson.stream.JsonWriter; * .registerSubtype(Circle.class) * .registerSubtype(Diamond.class); * } + * + *

Serialization and deserialization

+ * In order to serialize and deserialize a polymorphic object, + * you must specify the base type explicitly. + *
   {@code
+ *   Diamond diamond = new Diamond();
+ *   String json = gson.toJson(diamond, Shape.class);
+ * }
+ * And then: + *
   {@code
+ *   Shape shape = gson.fromJson(json, Shape.class);
+ * }
*/ public final class RuntimeTypeAdapterFactory implements TypeAdapterFactory { private final Class baseType;