org.spincast.plugins.gson.SpincastGsonPluginModule Maven / Gradle / Ivy
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 extends RequestContext>> requestContextImplementationClass,
Class extends WebsocketContext>> 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 extends JsonManager> getJsonManagerImpl() {
return SpincastGsonManager.class;
}
protected Class extends JsonPathUtils> getJsonPathUtilsImpl() {
return JsonPathUtilsDefault.class;
}
protected Class extends JsonDeserializer> getJsonObjectDeserializerImpl() {
return JsonObjectDeserializer.class;
}
protected Class extends JsonDeserializer> getJsonArrayDeserializerImpl() {
return JsonArrayDeserializer.class;
}
protected Class extends JsonSerializer> getJsonObjectSerializerImpl() {
return JsonObjectSerializer.class;
}
protected Class extends JsonSerializer> getJsonArraySerializerImpl() {
return JsonArraytSerializer.class;
}
protected Class extends JsonSerializer> getDateSerializerImpl() {
return DateSerializer.class;
}
protected Class extends JsonSerializer> getInstantSerializerImpl() {
return InstantSerializer.class;
}
protected Class extends JsonSerializer> getBigDecimalSerializerImpl() {
return BigDecimalSerializer.class;
}
protected Class extends JsonSerializer>> getEnumSerializerImpl() {
return EnumSerializer.class;
}
protected Class extends JsonSerializer>> getClassSerializerImpl() {
return ClassSerializer.class;
}
}