All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.spincast.plugins.gson.SpincastGsonPluginModule Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
package org.spincast.plugins.gson;

import java.math.BigDecimal;
import java.time.Instant;
import java.util.Date;

import org.spincast.core.exchange.RequestContext;
import org.spincast.core.guice.SpincastGuiceModuleBase;
import org.spincast.core.json.JsonArray;
import org.spincast.core.json.JsonManager;
import org.spincast.core.json.JsonObject;
import org.spincast.core.json.JsonPathUtils;
import org.spincast.core.json.JsonPathUtilsDefault;
import org.spincast.core.websocket.WebsocketContext;
import org.spincast.plugins.gson.serializers.BigDecimalSerializer;
import org.spincast.plugins.gson.serializers.ClassSerializer;
import org.spincast.plugins.gson.serializers.DateSerializer;
import org.spincast.plugins.gson.serializers.EnumSerializer;
import org.spincast.plugins.gson.serializers.InstantSerializer;
import org.spincast.plugins.gson.serializers.JsonArrayDeserializer;
import org.spincast.plugins.gson.serializers.JsonArraytSerializer;
import org.spincast.plugins.gson.serializers.JsonObjectDeserializer;
import org.spincast.plugins.gson.serializers.JsonObjectSerializer;

import com.google.gson.JsonDeserializer;
import com.google.gson.JsonSerializer;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;

/**
 * Spincast Gson plugin module.
 */
public class SpincastGsonPluginModule extends SpincastGuiceModuleBase {

    public SpincastGsonPluginModule() {
        super();
    }

    public SpincastGsonPluginModule(Class> requestContextImplementationClass,
                                    Class> websocketContextImplementationClass) {
        super(requestContextImplementationClass, websocketContextImplementationClass);
    }

    @Override
    protected void configure() {
        bind(JsonManager.class).to(getJsonManagerImpl()).in(Scopes.SINGLETON);
        bind(JsonPathUtils.class).to(getJsonPathUtilsImpl()).in(Scopes.SINGLETON);
        bind(new TypeLiteral>() {}).to(getJsonObjectDeserializerImpl()).in(Scopes.SINGLETON);
        bind(new TypeLiteral>() {}).to(getJsonArrayDeserializerImpl()).in(Scopes.SINGLETON);
        bind(new TypeLiteral>() {}).to(getJsonObjectSerializerImpl()).in(Scopes.SINGLETON);
        bind(new TypeLiteral>() {}).to(getJsonArraySerializerImpl()).in(Scopes.SINGLETON);
        bind(new TypeLiteral>() {}).to(getDateSerializerImpl()).in(Scopes.SINGLETON);
        bind(new TypeLiteral>() {}).to(getInstantSerializerImpl()).in(Scopes.SINGLETON);
        bind(new TypeLiteral>() {}).to(getBigDecimalSerializerImpl()).in(Scopes.SINGLETON);
        bind(new TypeLiteral>>() {}).to(getEnumSerializerImpl()).in(Scopes.SINGLETON);
        bind(new TypeLiteral>>() {}).to(getClassSerializerImpl()).in(Scopes.SINGLETON);

    }

    protected Class getJsonManagerImpl() {
        return SpincastGsonManager.class;
    }

    protected Class getJsonPathUtilsImpl() {
        return JsonPathUtilsDefault.class;
    }

    protected Class> getJsonObjectDeserializerImpl() {
        return JsonObjectDeserializer.class;
    }

    protected Class> getJsonArrayDeserializerImpl() {
        return JsonArrayDeserializer.class;
    }

    protected Class> getJsonObjectSerializerImpl() {
        return JsonObjectSerializer.class;
    }

    protected Class> getJsonArraySerializerImpl() {
        return JsonArraytSerializer.class;
    }

    protected Class> getDateSerializerImpl() {
        return DateSerializer.class;
    }

    protected Class> getInstantSerializerImpl() {
        return InstantSerializer.class;
    }

    protected Class> getBigDecimalSerializerImpl() {
        return BigDecimalSerializer.class;
    }

    protected Class>> getEnumSerializerImpl() {
        return EnumSerializer.class;
    }

    protected Class>> getClassSerializerImpl() {
        return ClassSerializer.class;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy