Docs fix for the RuntimeTypeAdapterFactory class.
Instances of classes that implement RuntimeTypeAdapterFactory should be registered using the registerTypeAdapterFactory method instead of registerTypeAdapter.
This commit is contained in:
parent
2360cfa05c
commit
d4a9eb4e7b
@ -97,7 +97,7 @@ import com.google.gson.stream.JsonWriter;
|
|||||||
* Create a {@code RuntimeTypeAdapterFactory} by passing the base type and type field
|
* Create a {@code RuntimeTypeAdapterFactory} by passing the base type and type field
|
||||||
* name to the {@link #of} factory method. If you don't supply an explicit type
|
* name to the {@link #of} factory method. If you don't supply an explicit type
|
||||||
* field name, {@code "type"} will be used. <pre> {@code
|
* field name, {@code "type"} will be used. <pre> {@code
|
||||||
* RuntimeTypeAdapterFactory<Shape> shapeAdapter
|
* RuntimeTypeAdapterFactory<Shape> shapeAdapterFactory
|
||||||
* = RuntimeTypeAdapterFactory.of(Shape.class, "type");
|
* = RuntimeTypeAdapterFactory.of(Shape.class, "type");
|
||||||
* }</pre>
|
* }</pre>
|
||||||
* Next register all of your subtypes. Every subtype must be explicitly
|
* Next register all of your subtypes. Every subtype must be explicitly
|
||||||
@ -108,14 +108,14 @@ import com.google.gson.stream.JsonWriter;
|
|||||||
* shapeAdapter.registerSubtype(Circle.class, "Circle");
|
* shapeAdapter.registerSubtype(Circle.class, "Circle");
|
||||||
* shapeAdapter.registerSubtype(Diamond.class, "Diamond");
|
* shapeAdapter.registerSubtype(Diamond.class, "Diamond");
|
||||||
* }</pre>
|
* }</pre>
|
||||||
* Finally, register the type adapter in your application's GSON builder:
|
* Finally, register the type adapter factory in your application's GSON builder:
|
||||||
* <pre> {@code
|
* <pre> {@code
|
||||||
* Gson gson = new GsonBuilder()
|
* Gson gson = new GsonBuilder()
|
||||||
* .registerTypeAdapter(Shape.class, shapeAdapter)
|
* .registerTypeAdapterFactory(Shape.class, shapeAdapterFactory)
|
||||||
* .create();
|
* .create();
|
||||||
* }</pre>
|
* }</pre>
|
||||||
* Like {@code GsonBuilder}, this API supports chaining: <pre> {@code
|
* Like {@code GsonBuilder}, this API supports chaining: <pre> {@code
|
||||||
* RuntimeTypeAdapterFactory<Shape> shapeAdapter = RuntimeTypeAdapterFactory.of(Shape.class)
|
* RuntimeTypeAdapterFactory<Shape> shapeAdapterFactory = RuntimeTypeAdapterFactory.of(Shape.class)
|
||||||
* .registerSubtype(Rectangle.class)
|
* .registerSubtype(Rectangle.class)
|
||||||
* .registerSubtype(Circle.class)
|
* .registerSubtype(Circle.class)
|
||||||
* .registerSubtype(Diamond.class);
|
* .registerSubtype(Diamond.class);
|
||||||
|
Loading…
Reference in New Issue
Block a user