diff --git a/gson/src/main/java/com/google/gson/GsonBuilder.java b/gson/src/main/java/com/google/gson/GsonBuilder.java index e6533e4d..db9e407f 100644 --- a/gson/src/main/java/com/google/gson/GsonBuilder.java +++ b/gson/src/main/java/com/google/gson/GsonBuilder.java @@ -16,11 +16,6 @@ package com.google.gson; -import com.google.gson.internal.$Gson$Preconditions; -import com.google.gson.internal.Excluder; -import com.google.gson.internal.Primitives; -import com.google.gson.internal.bind.TypeAdapters; -import com.google.gson.reflect.TypeToken; import java.lang.reflect.Type; import java.sql.Timestamp; import java.text.DateFormat; @@ -30,6 +25,12 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import com.google.gson.internal.$Gson$Preconditions; +import com.google.gson.internal.Excluder; +import com.google.gson.internal.Primitives; +import com.google.gson.internal.bind.TypeAdapters; +import com.google.gson.reflect.TypeToken; + /** *

Use this builder to construct a {@link Gson} instance when you need to set configuration * options other than the default. For {@link Gson} with default configuration, it is simpler to @@ -92,6 +93,32 @@ public final class GsonBuilder { public GsonBuilder() { } + /** + * Creates a deep copy of this instance: The collections for factories are deep copied, but the + * factories and type adapters themselves are not. + * + * @since 2.1 + */ + public GsonBuilder deepCopy() { + GsonBuilder copy = new GsonBuilder(); + copy.excluder = excluder; + copy.longSerializationPolicy = longSerializationPolicy; + copy.fieldNamingPolicy = fieldNamingPolicy; + copy.instanceCreators.putAll(instanceCreators); + copy.factories.addAll(factories); + copy.hierarchyFactories.addAll(hierarchyFactories); + copy.serializeNulls = serializeNulls; + copy.datePattern = datePattern; + copy.dateStyle = dateStyle; + copy.timeStyle = timeStyle; + copy.complexMapKeySerialization = complexMapKeySerialization; + copy.serializeSpecialFloatingPointValues = serializeSpecialFloatingPointValues; + copy.escapeHtmlChars = escapeHtmlChars; + copy.prettyPrinting = prettyPrinting; + copy.generateNonExecutableJson = generateNonExecutableJson; + return copy; + } + /** * Configures Gson to enable versioning support. * diff --git a/gson/src/main/java/com/google/gson/TypeAdapter.java b/gson/src/main/java/com/google/gson/TypeAdapter.java index 6e4bf7b5..66771399 100644 --- a/gson/src/main/java/com/google/gson/TypeAdapter.java +++ b/gson/src/main/java/com/google/gson/TypeAdapter.java @@ -76,6 +76,6 @@ public abstract class TypeAdapter { } public interface Factory { - TypeAdapter create(Gson context, TypeToken type); + TypeAdapter create(Gson gson, TypeToken type); } }