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

me.prettyprint.hom.converters.DefaultConverter Maven / Gradle / Ivy

There is a newer version: 3.0-04
Show newest version
package me.prettyprint.hom.converters;

import me.prettyprint.hector.api.Serializer;
import me.prettyprint.hom.HectorObjectMapper;
import me.prettyprint.hom.PropertyMappingDefinition;
import me.prettyprint.hom.annotations.Column;


/**
 * Default converter used when none specified in {@link Column} annotation. Uses
 * Java reflection to determine the Java type to use.
 * 
 * @author Todd Burruss
 */
public class DefaultConverter implements Converter {

  @Override
  public Object convertCassTypeToObjType(PropertyMappingDefinition md, byte[] value) {
    Serializer s = HectorObjectMapper.determineSerializer(md.getPropDesc().getPropertyType());
    return s.fromBytes(value);
  }

  @Override
  public byte[] convertObjTypeToCassType(Object value) {
    @SuppressWarnings("unchecked")
    Serializer s = (Serializer) HectorObjectMapper.determineSerializer(value.getClass());
    return s.toBytes(value);
  }

}