inlined typeAdapter and typeHierarchyAdapter methods. Added some documentation for registerTypeHierarchyAdapterFactory.

This commit is contained in:
Inderjeet Singh 2011-11-23 09:26:44 +00:00
parent 1794182a56
commit 1c09e24220

View File

@ -62,6 +62,7 @@ import java.util.Map;
*
* @author Inderjeet Singh
* @author Joel Leitch
* @author Jesse Wilson
*/
public final class GsonBuilder {
private Excluder excluder = Excluder.DEFAULT;
@ -93,12 +94,6 @@ public final class GsonBuilder {
public GsonBuilder() {
}
// TODO: nice documentation
public GsonBuilder registerTypeAdapterFactory(TypeAdapter.Factory factory) {
factories.add(factory);
return this;
}
/**
* Configures Gson to enable versioning support.
*
@ -464,14 +459,19 @@ public final class GsonBuilder {
factories.add(TreeTypeAdapter.newFactory(typeToken, typeAdapter));
}
if (typeAdapter instanceof TypeAdapter<?>) {
typeAdapter(TypeToken.get(type), (TypeAdapter)typeAdapter);
factories.add(TypeAdapters.newFactory(TypeToken.get(type), (TypeAdapter)typeAdapter));
}
return this;
}
// TODO: inline this method?
private <T> GsonBuilder typeAdapter(TypeToken<T> type, TypeAdapter<T> typeAdapter) {
factories.add(TypeAdapters.newFactory(type, typeAdapter));
/**
* Register a factory for type adapters. Registering a factory is useful when the type
* adapter needs to be configured based on the type of the field being processed. Gson
* is designed to handle a large number of factories, so you should consider registering
* them to be at par with registering an individual type adapter.
*/
public GsonBuilder registerTypeAdapterFactory(TypeAdapter.Factory factory) {
factories.add(factory);
return this;
}
@ -519,17 +519,11 @@ public final class GsonBuilder {
TreeTypeAdapter.newTypeHierarchyFactory(baseType, typeAdapter));
}
if (typeAdapter instanceof TypeAdapter<?>) {
typeHierarchyAdapter(baseType, (TypeAdapter)typeAdapter);
factories.add(TypeAdapters.newTypeHierarchyFactory(baseType, (TypeAdapter)typeAdapter));
}
return this;
}
// TODO: inline this method?
private <T> GsonBuilder typeHierarchyAdapter(Class<T> type, TypeAdapter<T> typeAdapter) {
factories.add(TypeAdapters.newTypeHierarchyFactory(type, typeAdapter));
return this;
}
/**
* Section 2.4 of <a href="http://www.ietf.org/rfc/rfc4627.txt">JSON specification</a> disallows
* special double values (NaN, Infinity, -Infinity). However,