diff --git a/core/src/main/java/org/jclouds/json/config/GsonModule.java b/core/src/main/java/org/jclouds/json/config/GsonModule.java index b0d1e35661..fa2728f5b6 100644 --- a/core/src/main/java/org/jclouds/json/config/GsonModule.java +++ b/core/src/main/java/org/jclouds/json/config/GsonModule.java @@ -102,10 +102,10 @@ public class GsonModule extends AbstractModule { builder.registerTypeAdapter(byte[].class, byteArrayAdapter.nullSafe()); builder.registerTypeAdapter(JsonBall.class, jsonAdapter.nullSafe()); builder.registerTypeAdapterFactory(optional); + builder.registerTypeAdapterFactory(iterable); builder.registerTypeAdapterFactory(set); builder.registerTypeAdapterFactory(map); builder.registerTypeAdapterFactory(multimap); - builder.registerTypeAdapterFactory(iterable); builder.registerTypeAdapterFactory(fluentIterable); AnnotationConstructorNamingStrategy deserializationPolicy = diff --git a/core/src/main/java/org/jclouds/json/internal/IgnoreNullFluentIterableTypeAdapterFactory.java b/core/src/main/java/org/jclouds/json/internal/IgnoreNullFluentIterableTypeAdapterFactory.java index ad5d9a15b1..42d31e28e1 100644 --- a/core/src/main/java/org/jclouds/json/internal/IgnoreNullFluentIterableTypeAdapterFactory.java +++ b/core/src/main/java/org/jclouds/json/internal/IgnoreNullFluentIterableTypeAdapterFactory.java @@ -53,7 +53,7 @@ public class IgnoreNullFluentIterableTypeAdapterFactory implements TypeAdapterFa return (TypeAdapter) newFluentIterableAdapter(elementAdapter); } - private TypeAdapter> newFluentIterableAdapter(final TypeAdapter elementAdapter) { + protected TypeAdapter> newFluentIterableAdapter(final TypeAdapter elementAdapter) { return new TypeAdapter>() { public void write(JsonWriter out, FluentIterable value) throws IOException { out.beginArray(); diff --git a/core/src/main/java/org/jclouds/json/internal/IgnoreNullIterableTypeAdapterFactory.java b/core/src/main/java/org/jclouds/json/internal/IgnoreNullIterableTypeAdapterFactory.java index 34ca42d2d3..f4c88fbadb 100644 --- a/core/src/main/java/org/jclouds/json/internal/IgnoreNullIterableTypeAdapterFactory.java +++ b/core/src/main/java/org/jclouds/json/internal/IgnoreNullIterableTypeAdapterFactory.java @@ -52,7 +52,7 @@ public class IgnoreNullIterableTypeAdapterFactory implements TypeAdapterFactory return (TypeAdapter) newIterableAdapter(elementAdapter); } - private TypeAdapter> newIterableAdapter(final TypeAdapter elementAdapter) { + protected TypeAdapter> newIterableAdapter(final TypeAdapter elementAdapter) { return new TypeAdapter>() { public void write(JsonWriter out, Iterable value) throws IOException { out.beginArray(); @@ -63,7 +63,7 @@ public class IgnoreNullIterableTypeAdapterFactory implements TypeAdapterFactory } public Iterable read(JsonReader in) throws IOException { - in.beginArray(); + in.beginArray(); Builder builder = ImmutableList.builder(); while (in.hasNext()) { E element = elementAdapter.read(in); diff --git a/core/src/main/java/org/jclouds/json/internal/IgnoreNullMapTypeAdapterFactory.java b/core/src/main/java/org/jclouds/json/internal/IgnoreNullMapTypeAdapterFactory.java index 7fcfb2b9d3..71d032f631 100644 --- a/core/src/main/java/org/jclouds/json/internal/IgnoreNullMapTypeAdapterFactory.java +++ b/core/src/main/java/org/jclouds/json/internal/IgnoreNullMapTypeAdapterFactory.java @@ -54,7 +54,7 @@ public class IgnoreNullMapTypeAdapterFactory implements TypeAdapterFactory { return (TypeAdapter) newMapAdapter(keyAdapter, valueAdapter); } - private TypeAdapter> newMapAdapter(final TypeAdapter keyAdapter, final TypeAdapter valueAdapter) { + protected TypeAdapter> newMapAdapter(final TypeAdapter keyAdapter, final TypeAdapter valueAdapter) { return new TypeAdapter>() { public void write(JsonWriter out, Map value) throws IOException { out.beginObject(); diff --git a/core/src/main/java/org/jclouds/json/internal/IgnoreNullMultimapTypeAdapterFactory.java b/core/src/main/java/org/jclouds/json/internal/IgnoreNullMultimapTypeAdapterFactory.java index 77938bda58..6a2827c407 100644 --- a/core/src/main/java/org/jclouds/json/internal/IgnoreNullMultimapTypeAdapterFactory.java +++ b/core/src/main/java/org/jclouds/json/internal/IgnoreNullMultimapTypeAdapterFactory.java @@ -51,10 +51,10 @@ public class IgnoreNullMultimapTypeAdapterFactory implements TypeAdapterFactory Type valueType = ((ParameterizedType) type).getActualTypeArguments()[1]; TypeAdapter keyAdapter = gson.getAdapter(TypeToken.get(keyType)); TypeAdapter valueAdapter = gson.getAdapter(TypeToken.get(valueType)); - return (TypeAdapter) newMapAdapter(keyAdapter, valueAdapter); + return (TypeAdapter) newMultimapAdapter(keyAdapter, valueAdapter); } - private TypeAdapter> newMapAdapter(final TypeAdapter keyAdapter, final TypeAdapter valueAdapter) { + protected TypeAdapter> newMultimapAdapter(final TypeAdapter keyAdapter, final TypeAdapter valueAdapter) { return new TypeAdapter>() { public void write(JsonWriter out, Multimap map) throws IOException { out.beginObject(); diff --git a/core/src/main/java/org/jclouds/json/internal/IgnoreNullSetTypeAdapterFactory.java b/core/src/main/java/org/jclouds/json/internal/IgnoreNullSetTypeAdapterFactory.java index 393a710f3a..1ae22c367f 100644 --- a/core/src/main/java/org/jclouds/json/internal/IgnoreNullSetTypeAdapterFactory.java +++ b/core/src/main/java/org/jclouds/json/internal/IgnoreNullSetTypeAdapterFactory.java @@ -23,7 +23,7 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.Set; -import com.google.common.collect.Sets; +import com.google.common.collect.ImmutableSet; import com.google.gson.Gson; import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapterFactory; @@ -32,7 +32,7 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; /** - * Eliminates null values when deserializing Sets + * Eliminates null values when deserializing Sets. *

* Treats [null] as the empty set; [A, null] as [A]; etc. * @@ -52,7 +52,7 @@ public class IgnoreNullSetTypeAdapterFactory implements TypeAdapterFactory { return (TypeAdapter) newSetAdapter(elementAdapter); } - private TypeAdapter> newSetAdapter(final TypeAdapter elementAdapter) { + protected TypeAdapter> newSetAdapter(final TypeAdapter elementAdapter) { return new TypeAdapter>() { public void write(JsonWriter out, Set value) throws IOException { out.beginArray(); @@ -63,14 +63,15 @@ public class IgnoreNullSetTypeAdapterFactory implements TypeAdapterFactory { } public Set read(JsonReader in) throws IOException { - Set result = Sets.newLinkedHashSet(); + ImmutableSet.Builder result = ImmutableSet. builder(); in.beginArray(); while (in.hasNext()) { E element = elementAdapter.read(in); - if (element != null) result.add(element); + if (element != null) + result.add(element); } in.endArray(); - return result; + return result.build(); } }.nullSafe(); } diff --git a/core/src/main/java/org/jclouds/json/internal/OptionalTypeAdapterFactory.java b/core/src/main/java/org/jclouds/json/internal/OptionalTypeAdapterFactory.java index 1855e8e7db..0e57f8eaaf 100644 --- a/core/src/main/java/org/jclouds/json/internal/OptionalTypeAdapterFactory.java +++ b/core/src/main/java/org/jclouds/json/internal/OptionalTypeAdapterFactory.java @@ -48,10 +48,10 @@ public class OptionalTypeAdapterFactory implements TypeAdapterFactory { Type elementType = ((ParameterizedType) type).getActualTypeArguments()[0]; TypeAdapter elementAdapter = gson.getAdapter(TypeToken.get(elementType)); - return (TypeAdapter) newMultisetAdapter(elementAdapter); + return (TypeAdapter) newOptionalAdapter(elementAdapter); } - private TypeAdapter> newMultisetAdapter( + protected TypeAdapter> newOptionalAdapter( final TypeAdapter elementAdapter) { return new TypeAdapter>() { public void write(JsonWriter out, Optional value) throws IOException {