From 00ff5b794af1588e3a261fb862728244972f659c Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 27 Oct 2014 23:17:03 -0700 Subject: [PATCH] Accidentally set limited json fallback field naming to an enum. --- .../org/jclouds/json/config/GsonModule.java | 86 ++++++++++--------- .../json/internal/NamingStrategies.java | 7 +- .../test/java/org/jclouds/json/JsonTest.java | 5 +- 3 files changed, 50 insertions(+), 48 deletions(-) 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 9aebbe97a9..1dd53dafd7 100644 --- a/core/src/main/java/org/jclouds/json/config/GsonModule.java +++ b/core/src/main/java/org/jclouds/json/config/GsonModule.java @@ -16,6 +16,45 @@ */ package org.jclouds.json.config; +import static com.google.common.io.BaseEncoding.base16; + +import java.beans.ConstructorProperties; +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.Date; +import java.util.Enumeration; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import javax.inject.Provider; +import javax.inject.Singleton; + +import org.jclouds.date.DateService; +import org.jclouds.domain.JsonBall; +import org.jclouds.json.Json; +import org.jclouds.json.SerializedNames; +import org.jclouds.json.internal.DeserializationConstructorAndReflectiveTypeAdapterFactory; +import org.jclouds.json.internal.EnumTypeAdapterThatReturnsFromValue; +import org.jclouds.json.internal.GsonWrapper; +import org.jclouds.json.internal.NamingStrategies.AnnotationConstructorNamingStrategy; +import org.jclouds.json.internal.NamingStrategies.AnnotationOrNameFieldNamingStrategy; +import org.jclouds.json.internal.NamingStrategies.ExtractNamed; +import org.jclouds.json.internal.NamingStrategies.ExtractSerializedName; +import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.CollectionTypeAdapterFactory; +import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.FluentIterableTypeAdapterFactory; +import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.ImmutableListTypeAdapterFactory; +import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.ImmutableMapTypeAdapterFactory; +import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.ImmutableSetTypeAdapterFactory; +import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.IterableTypeAdapterFactory; +import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.ListTypeAdapterFactory; +import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.MapTypeAdapterFactory; +import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.MultimapTypeAdapterFactory; +import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.SetTypeAdapterFactory; +import org.jclouds.json.internal.NullHackJsonLiteralAdapter; +import org.jclouds.json.internal.OptionalTypeAdapterFactory; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.ImmutableSet; @@ -41,50 +80,13 @@ import com.google.inject.AbstractModule; import com.google.inject.ImplementedBy; import com.google.inject.Inject; import com.google.inject.Provides; -import org.jclouds.date.DateService; -import org.jclouds.domain.JsonBall; -import org.jclouds.json.Json; -import org.jclouds.json.SerializedNames; -import org.jclouds.json.internal.DeserializationConstructorAndReflectiveTypeAdapterFactory; -import org.jclouds.json.internal.EnumTypeAdapterThatReturnsFromValue; -import org.jclouds.json.internal.GsonWrapper; -import org.jclouds.json.internal.NamingStrategies.AnnotationConstructorNamingStrategy; -import org.jclouds.json.internal.NamingStrategies.AnnotationOrNameFieldNamingStrategy; -import org.jclouds.json.internal.NamingStrategies.ExtractNamed; -import org.jclouds.json.internal.NamingStrategies.ExtractSerializedName; -import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.ImmutableMapTypeAdapterFactory; -import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.CollectionTypeAdapterFactory; -import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.FluentIterableTypeAdapterFactory; -import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.ImmutableListTypeAdapterFactory; -import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.ImmutableSetTypeAdapterFactory; -import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.IterableTypeAdapterFactory; -import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.ListTypeAdapterFactory; -import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.MapTypeAdapterFactory; -import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.MultimapTypeAdapterFactory; -import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.SetTypeAdapterFactory; -import org.jclouds.json.internal.NullHackJsonLiteralAdapter; -import org.jclouds.json.internal.OptionalTypeAdapterFactory; - -import javax.inject.Provider; -import javax.inject.Singleton; -import java.beans.ConstructorProperties; -import java.io.IOException; -import java.lang.reflect.Type; -import java.util.Date; -import java.util.Enumeration; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import static com.google.common.io.BaseEncoding.base16; public class GsonModule extends AbstractModule { - /** Optionally override the fallback policy when name annotations aren't on fields. */ - private static class FallbackFieldNamingPolicy { + /** Optionally override the fallback field naming strategy when name annotations aren't on fields. */ + private static class FallbackFieldNamingStrategy { @Inject(optional = true) - FieldNamingPolicy fallback = FieldNamingPolicy.IDENTITY; + FieldNamingStrategy fallback = FieldNamingPolicy.IDENTITY; } @SuppressWarnings("rawtypes") @@ -97,10 +99,10 @@ public class GsonModule extends AbstractModule { CollectionTypeAdapterFactory collection, ListTypeAdapterFactory list, ImmutableListTypeAdapterFactory immutableList, FluentIterableTypeAdapterFactory fluentIterable, ImmutableMapTypeAdapterFactory immutableMap, DefaultExclusionStrategy exclusionStrategy, - FallbackFieldNamingPolicy fallbackFieldNamingPolicy) { + FallbackFieldNamingStrategy fallbackFieldNamingStrategy) { FieldNamingStrategy serializationPolicy = new AnnotationOrNameFieldNamingStrategy(ImmutableSet.of( - new ExtractSerializedName(), new ExtractNamed()), fallbackFieldNamingPolicy.fallback); + new ExtractSerializedName(), new ExtractNamed()), fallbackFieldNamingStrategy.fallback); GsonBuilder builder = new GsonBuilder().setFieldNamingStrategy(serializationPolicy) .setExclusionStrategies(exclusionStrategy); diff --git a/core/src/main/java/org/jclouds/json/internal/NamingStrategies.java b/core/src/main/java/org/jclouds/json/internal/NamingStrategies.java index c3931a1de3..5f4ed893fc 100644 --- a/core/src/main/java/org/jclouds/json/internal/NamingStrategies.java +++ b/core/src/main/java/org/jclouds/json/internal/NamingStrategies.java @@ -43,7 +43,6 @@ import com.google.common.collect.FluentIterable; import com.google.common.collect.Maps; import com.google.common.reflect.Invokable; import com.google.common.reflect.TypeToken; -import com.google.gson.FieldNamingPolicy; import com.google.gson.FieldNamingStrategy; import com.google.gson.annotations.SerializedName; @@ -163,10 +162,10 @@ public class NamingStrategies { public static class AnnotationFieldNamingStrategy extends AnnotationBasedNamingStrategy implements FieldNamingStrategy { - private final FieldNamingPolicy fallback; + private final FieldNamingStrategy fallback; public AnnotationFieldNamingStrategy(Iterable> extractors, - FieldNamingPolicy fallback) { + FieldNamingStrategy fallback) { super(extractors); checkArgument(extractors.iterator().hasNext(), "you must supply at least one name extractor, for example: " + ExtractSerializedName.class.getSimpleName()); @@ -188,7 +187,7 @@ public class NamingStrategies { FieldNamingStrategy { public AnnotationOrNameFieldNamingStrategy(Iterable> extractors, - FieldNamingPolicy fallback) { + FieldNamingStrategy fallback) { super(extractors, fallback); } diff --git a/core/src/test/java/org/jclouds/json/JsonTest.java b/core/src/test/java/org/jclouds/json/JsonTest.java index 3a559dbc00..6a0b6aa360 100644 --- a/core/src/test/java/org/jclouds/json/JsonTest.java +++ b/core/src/test/java/org/jclouds/json/JsonTest.java @@ -35,6 +35,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.gson.FieldAttributes; import com.google.gson.FieldNamingPolicy; +import com.google.gson.FieldNamingStrategy; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.TypeLiteral; @@ -228,7 +229,7 @@ public class JsonTest { public void upperCamelCaseWithSerializedNames() { Json json = Guice.createInjector(new GsonModule(), new AbstractModule() { @Override protected void configure() { - bind(FieldNamingPolicy.class).toInstance(FieldNamingPolicy.UPPER_CAMEL_CASE); + bind(FieldNamingStrategy.class).toInstance(FieldNamingPolicy.UPPER_CAMEL_CASE); } }).getInstance(Json.class); @@ -242,7 +243,7 @@ public class JsonTest { public void upperCamelCaseWithSerializedNamesNullJsonValue() { Json json = Guice.createInjector(new GsonModule(), new AbstractModule() { @Override protected void configure() { - bind(FieldNamingPolicy.class).toInstance(FieldNamingPolicy.UPPER_CAMEL_CASE); + bind(FieldNamingStrategy.class).toInstance(FieldNamingPolicy.UPPER_CAMEL_CASE); } }).getInstance(Json.class);