Example usage for com.google.gson.internal ConstructorConstructor ConstructorConstructor

List of usage examples for com.google.gson.internal ConstructorConstructor ConstructorConstructor

Introduction

In this page you can find the example usage for com.google.gson.internal ConstructorConstructor ConstructorConstructor.

Prototype

public ConstructorConstructor(Map<Type, InstanceCreator<?>> instanceCreators) 

Source Link

Usage

From source file:com.spbsu.exp.dl.GraphAdapterBuilder.java

License:Apache License

public GraphAdapterBuilder() {
    this.instanceCreators = new HashMap<Type, InstanceCreator<?>>();
    this.constructorConstructor = new ConstructorConstructor(instanceCreators);
}

From source file:com.thirstygoat.kiqo.persistence.GraphAdapterBuilder.java

License:Apache License

public GraphAdapterBuilder() {
    instanceCreators = new HashMap<Type, InstanceCreator<?>>();
    constructorConstructor = new ConstructorConstructor(instanceCreators);
}

From source file:edu.mit.media.funf.config.DefaultRuntimeTypeAdapterFactory.java

License:Open Source License

/**
 * @param context//from  w  w  w  .  j  a  v a  2s . c  om
 * @param baseClass  
 * @param defaultClass  Setting this to null will cause a ParseException if the runtime type information is incorrect or unavailable.
 */
public DefaultRuntimeTypeAdapterFactory(Context context, Class<E> baseClass, Class<? extends E> defaultClass,
        TypeAdapterFactory delegateFactory) {
    assert context != null && baseClass != null;
    if (defaultClass != null && !isInstantiable(defaultClass)) {
        throw new RuntimeException("Default class does not have a default contructor.");
    }
    this.context = context;
    this.baseClass = baseClass;
    this.defaultClass = defaultClass;
    if (delegateFactory == null) {
        this.delegateFactory = new ReflectiveTypeAdapterFactory(
                new ConstructorConstructor(Collections.<Type, InstanceCreator<?>>emptyMap()),
                FieldNamingPolicy.IDENTITY, Excluder.DEFAULT);
    } else {
        this.delegateFactory = delegateFactory;
    }
}

From source file:org.eclipse.smarthome.storage.json.PropertiesTypeAdapter.java

License:Open Source License

public PropertiesTypeAdapter(Gson gson) {
    // obtain the default type adapters for String and Object classes
    keyAdapter = gson.getAdapter(String.class);
    valueAdapter = gson.getAdapter(Object.class);

    // obtain default gson objects
    constructor = new ConstructorConstructor(Collections.<Type, InstanceCreator<?>>emptyMap());
    delegate = new MapTypeAdapterFactory(constructor, false).create(new Gson(), TOKEN);
}

From source file:org.jclouds.json.config.GsonModule.java

License:Apache License

@SuppressWarnings("rawtypes")
@Provides/*from w w w  .  j av a 2  s.c  o m*/
@Singleton
Gson provideGson(TypeAdapter<JsonBall> jsonAdapter, DateAdapter adapter, ByteListAdapter byteListAdapter,
        ByteArrayAdapter byteArrayAdapter, PropertiesAdapter propertiesAdapter, JsonAdapterBindings bindings,
        CredentialsAdapterFactory credentialsAdapterFactory, OptionalTypeAdapterFactory optional,
        SetTypeAdapterFactory set, ImmutableSetTypeAdapterFactory immutableSet, MapTypeAdapterFactory map,
        MultimapTypeAdapterFactory multimap, IterableTypeAdapterFactory iterable,
        CollectionTypeAdapterFactory collection, ListTypeAdapterFactory list,
        ImmutableListTypeAdapterFactory immutableList, FluentIterableTypeAdapterFactory fluentIterable,
        ImmutableMapTypeAdapterFactory immutableMap, DefaultExclusionStrategy exclusionStrategy) {

    FieldNamingStrategy serializationPolicy = new AnnotationOrNameFieldNamingStrategy(
            ImmutableSet.of(new ExtractSerializedName(), new ExtractNamed()));

    GsonBuilder builder = new GsonBuilder().setFieldNamingStrategy(serializationPolicy)
            .setExclusionStrategies(exclusionStrategy);

    // simple (type adapters)
    builder.registerTypeAdapter(Properties.class, propertiesAdapter.nullSafe());
    builder.registerTypeAdapter(Date.class, adapter.nullSafe());
    builder.registerTypeAdapter(byte[].class, byteArrayAdapter.nullSafe());
    builder.registerTypeAdapter(JsonBall.class, jsonAdapter.nullSafe());
    builder.registerTypeAdapterFactory(credentialsAdapterFactory);
    builder.registerTypeAdapterFactory(optional);
    builder.registerTypeAdapterFactory(iterable);
    builder.registerTypeAdapterFactory(collection);
    builder.registerTypeAdapterFactory(list);
    builder.registerTypeAdapter(new TypeToken<List<Byte>>() {
    }.getType(), byteListAdapter.nullSafe());
    builder.registerTypeAdapterFactory(immutableList);
    builder.registerTypeAdapterFactory(set);
    builder.registerTypeAdapterFactory(immutableSet);
    builder.registerTypeAdapterFactory(map);
    builder.registerTypeAdapterFactory(multimap);
    builder.registerTypeAdapterFactory(fluentIterable);
    builder.registerTypeAdapterFactory(immutableMap);

    AnnotationConstructorNamingStrategy deserializationPolicy = new AnnotationConstructorNamingStrategy(
            ImmutableSet.of(ConstructorProperties.class, SerializedNames.class, Inject.class),
            ImmutableSet.of(new ExtractNamed()));

    builder.registerTypeAdapterFactory(new DeserializationConstructorAndReflectiveTypeAdapterFactory(
            new ConstructorConstructor(ImmutableMap.<Type, InstanceCreator<?>>of()), serializationPolicy,
            Excluder.DEFAULT, deserializationPolicy));

    // complicated (serializers/deserializers as they need context to operate)
    builder.registerTypeHierarchyAdapter(Enum.class, new EnumTypeAdapterThatReturnsFromValue());

    for (Map.Entry<Type, Object> binding : bindings.getBindings().entrySet()) {
        builder.registerTypeAdapter(binding.getKey(), binding.getValue());
    }

    for (TypeAdapterFactory factory : bindings.getFactories()) {
        builder.registerTypeAdapterFactory(factory);
    }

    return builder.create();
}