org.jclouds.json.internal
Class DeserializationConstructorAndReflectiveTypeAdapterFactory

java.lang.Object
  extended by org.jclouds.json.internal.DeserializationConstructorAndReflectiveTypeAdapterFactory
All Implemented Interfaces:
com.google.gson.TypeAdapterFactory

public final class DeserializationConstructorAndReflectiveTypeAdapterFactory
extends Object
implements com.google.gson.TypeAdapterFactory

Creates type adapters for types handled in the following ways:

Example: Using javax inject to select a constructor and corresponding named parameters

    
 import NamingStrategies.*;

 serializationStrategy = new AnnotationOrNameFieldNamingStrategy(
    new ExtractSerializedName(), new ExtractNamed());
 
 deserializationStrategy = new AnnotationConstructorNamingStrategy(
    Collections.singleton(javax.inject.Inject.class),
    Collections.singleton(new ExtractNamed()));
    
 factory = new DeserializationConstructorAndReflectiveTypeAdapterFactory(new ConstructorConstructor(),
      serializationStrategy, Excluder.DEFAULT, deserializationStrategy);

 gson = new GsonBuilder(serializationStrategy).registerTypeAdapterFactory(factory).create();

 

The above would work fine on the following class, which has no gson-specific annotations:

 private static class ImmutableAndVerifiedInCtor {
    final int foo;
    @Named("_bar")
    final int bar;

    @Inject
    ImmutableAndVerifiedInCtor(@Named("foo") int foo, @Named("_bar") int bar) {
       if (foo < 0)
          throw new IllegalArgumentException("negative!");
       this.foo = foo;
       this.bar = bar;
    }
 }
 


Author:
Adrian Cole, Adam Lowe

Constructor Summary
DeserializationConstructorAndReflectiveTypeAdapterFactory(com.google.gson.internal.ConstructorConstructor constructorConstructor, com.google.gson.FieldNamingStrategy serializationFieldNamingPolicy, com.google.gson.internal.Excluder excluder, NamingStrategies.ConstructorFieldNamingStrategy deserializationFieldNamingPolicy)
           
 
Method Summary
<T> com.google.gson.TypeAdapter<T>
create(com.google.gson.Gson gson, com.google.gson.reflect.TypeToken<T> type)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DeserializationConstructorAndReflectiveTypeAdapterFactory

public DeserializationConstructorAndReflectiveTypeAdapterFactory(com.google.gson.internal.ConstructorConstructor constructorConstructor,
                                                                 com.google.gson.FieldNamingStrategy serializationFieldNamingPolicy,
                                                                 com.google.gson.internal.Excluder excluder,
                                                                 NamingStrategies.ConstructorFieldNamingStrategy deserializationFieldNamingPolicy)
Parameters:
constructorConstructor - passed through to delegate ReflectiveTypeAdapterFactory for serialization
serializationFieldNamingPolicy - passed through to delegate ReflectiveTypeAdapterFactory for serialization
excluder - passed through to delegate ReflectiveTypeAdapterFactory for serialization
deserializationFieldNamingPolicy - determines which constructor to use and how to determine field names for deserialization
See Also:
ReflectiveTypeAdapterFactory
Method Detail

create

public <T> com.google.gson.TypeAdapter<T> create(com.google.gson.Gson gson,
                                                 com.google.gson.reflect.TypeToken<T> type)
Specified by:
create in interface com.google.gson.TypeAdapterFactory


Copyright © 2009-2013 jclouds. All Rights Reserved.