use of me.prettyprint.hector.api.Serializer in project gora by apache.
the class GoraSerializerTypeInferer method getSerializer.
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> Serializer<T> getSerializer(Object value) {
Serializer serializer = null;
if (value == null) {
serializer = ByteBufferSerializer.get();
} else if (value instanceof CharSequence) {
serializer = CharSequenceSerializer.get();
} else if (value instanceof Utf8) {
serializer = CharSequenceSerializer.get();
} else if (value instanceof Boolean) {
serializer = BooleanSerializer.get();
} else if (value instanceof ByteBuffer) {
serializer = ByteBufferSerializer.get();
} else if (value instanceof byte[]) {
serializer = BytesArraySerializer.get();
} else if (value instanceof Double) {
serializer = DoubleSerializer.get();
} else if (value instanceof Float) {
serializer = FloatSerializer.get();
} else if (value instanceof Integer) {
serializer = IntegerSerializer.get();
} else if (value instanceof Long) {
serializer = LongSerializer.get();
} else if (value instanceof String) {
serializer = StringSerializer.get();
} else if (value instanceof SpecificFixed) {
serializer = SpecificFixedSerializer.get(value.getClass());
} else if (value instanceof GenericArray) {
Schema schema = ((GenericArray) value).getSchema();
if (schema.getType() == Type.ARRAY) {
schema = schema.getElementType();
}
serializer = ListSerializer.get(schema);
} else if (value instanceof Map) {
Map map = (Map) value;
if (map.size() == 0) {
serializer = ByteBufferSerializer.get();
} else {
Object value0 = map.values().iterator().next();
Schema schema = TypeUtils.getSchema(value0);
serializer = MapSerializer.get(schema);
}
} else if (value instanceof Persistent) {
serializer = ObjectSerializer.get();
} else {
serializer = SerializerTypeInferer.getSerializer(value);
}
return serializer;
}
use of me.prettyprint.hector.api.Serializer in project gora by apache.
the class GoraSerializerTypeInferer method getSerializer.
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> Serializer<T> getSerializer(Schema schema) {
Serializer serializer = null;
Type type = schema.getType();
if (type.equals(Type.STRING)) {
serializer = CharSequenceSerializer.get();
} else if (type.equals(Type.BOOLEAN)) {
serializer = BooleanSerializer.get();
} else if (type.equals(Type.BYTES)) {
serializer = ByteBufferSerializer.get();
} else if (type.equals(Type.DOUBLE)) {
serializer = DoubleSerializer.get();
} else if (type.equals(Type.FLOAT)) {
serializer = FloatSerializer.get();
} else if (type.equals(Type.INT)) {
serializer = IntegerSerializer.get();
} else if (type.equals(Type.LONG)) {
serializer = LongSerializer.get();
} else if (type.equals(Type.FIXED)) {
Class clazz = TypeUtils.getClass(schema);
serializer = SpecificFixedSerializer.get(clazz);
// serializer = SpecificFixedSerializer.get(schema);
} else if (type.equals(Type.ARRAY)) {
serializer = ListSerializer.get(schema.getElementType());
} else if (type.equals(Type.MAP)) {
serializer = MapSerializer.get(schema.getValueType());
} else if (type.equals(Type.UNION)) {
serializer = ByteBufferSerializer.get();
} else if (type.equals(Type.RECORD)) {
serializer = BytesArraySerializer.get();
} else {
serializer = null;
}
return serializer;
}
Aggregations