diff --git a/gson/src/main/java/com/google/gson/GsonBuilder.java b/gson/src/main/java/com/google/gson/GsonBuilder.java index 0c917d46..cebed7e7 100644 --- a/gson/src/main/java/com/google/gson/GsonBuilder.java +++ b/gson/src/main/java/com/google/gson/GsonBuilder.java @@ -16,7 +16,6 @@ package com.google.gson; -import com.google.gson.stream.JsonReader; import java.lang.reflect.Type; import java.sql.Timestamp; import java.text.DateFormat; @@ -32,6 +31,7 @@ import com.google.gson.internal.Excluder; import com.google.gson.internal.bind.TreeTypeAdapter; import com.google.gson.internal.bind.TypeAdapters; import com.google.gson.reflect.TypeToken; +import com.google.gson.stream.JsonReader; import static com.google.gson.Gson.DEFAULT_COMPLEX_MAP_KEYS; import static com.google.gson.Gson.DEFAULT_ESCAPE_HTML; @@ -519,8 +519,7 @@ public final class GsonBuilder { || typeAdapter instanceof JsonDeserializer || typeAdapter instanceof TypeAdapter); if (typeAdapter instanceof JsonDeserializer || typeAdapter instanceof JsonSerializer) { - hierarchyFactories.add(0, - TreeTypeAdapter.newTypeHierarchyFactory(baseType, typeAdapter)); + hierarchyFactories.add(TreeTypeAdapter.newTypeHierarchyFactory(baseType, typeAdapter)); } if (typeAdapter instanceof TypeAdapter) { factories.add(TypeAdapters.newTypeHierarchyFactory(baseType, (TypeAdapter)typeAdapter)); @@ -560,9 +559,10 @@ public final class GsonBuilder { * @return an instance of Gson configured with the options currently set in this builder */ public Gson create() { - List factories = new ArrayList(); + List factories = new ArrayList(this.factories.size() + this.hierarchyFactories.size() + 3); factories.addAll(this.factories); Collections.reverse(factories); + Collections.reverse(this.hierarchyFactories); factories.addAll(this.hierarchyFactories); addTypeAdaptersForDate(datePattern, dateStyle, timeStyle, factories); diff --git a/proto/src/main/java/com/google/gson/protobuf/ProtoTypeAdapter.java b/proto/src/main/java/com/google/gson/protobuf/ProtoTypeAdapter.java index 4fba080d..5570edc9 100644 --- a/proto/src/main/java/com/google/gson/protobuf/ProtoTypeAdapter.java +++ b/proto/src/main/java/com/google/gson/protobuf/ProtoTypeAdapter.java @@ -270,7 +270,7 @@ public class ProtoTypeAdapter if (jsonElement.isJsonArray()) { // Handling array Collection enumCollection = - new ArrayList(); + new ArrayList(jsonElement.getAsJsonArray().size()); for (JsonElement element : jsonElement.getAsJsonArray()) { enumCollection.add( findValueByNameAndExtension(fieldDescriptor.getEnumType(), element));