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

com.flipkart.hbaseobjectmapper.codec.Codec Maven / Gradle / Ivy

Go to download

HBase ORM is a light-weight, thread-safe and performant library that enables: [1] object-oriented access of HBase rows (Data Access Object) with minimal code and good testability [2] reading from and/or writing to HBase tables in Hadoop MapReduce jobs

There is a newer version: 1.19
Show newest version
package com.flipkart.hbaseobjectmapper.codec;


import com.flipkart.hbaseobjectmapper.HBObjectMapper;
import com.flipkart.hbaseobjectmapper.codec.exceptions.DeserializationException;
import com.flipkart.hbaseobjectmapper.codec.exceptions.SerializationException;

import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.Map;

/**
 * Interface that defines serialization and deserialization behavior for {@link HBObjectMapper HBObjectMapper}
 */
public interface Codec {
    /**
     * Serializes object to a byte[]
     *
     * @param object Object to be serialized
     * @param flags  Flags for tuning serialization behavior (Implementations of this method are expected to handle null and empty map in the same way)
     * @return byte array - this would be used 'as is' in setting the column value in HBase row
     * @throws SerializationException If serialization fails (e.g. when input object has a field of data type that isn't serializable by this codec)
     * @see #deserialize(byte[], Type, Map)
     */
    byte[] serialize(Serializable object, Map flags) throws SerializationException;

    /**
     * Deserialize byte[] into an object
     *
     * @param bytes byte array that needs to be deserialized
     * @param flags Flags for tuning deserialization behavior  (Implementations of this method are expected to handle null and empty map in the same way)
     * @param type  Java type to which this byte[] needs to be deserialized to
     * @return The object
     * @throws DeserializationException If deserialization fails (e.g. malformed string or definition of a data type used isn't available at runtime)
     * @see #serialize(Serializable, Map)
     * @see #canDeserialize(Type)
     */
    Serializable deserialize(byte[] bytes, Type type, Map flags) throws DeserializationException;

    /**
     * Check whether a specific type can be deserialized using this codec
     *
     * @param type Java type
     * @return true (if an object of specified type can be deserialized using this codec) or false
     * @see #deserialize(byte[], Type, Map)
     */
    @SuppressWarnings("BooleanMethodIsAlwaysInverted")
    boolean canDeserialize(Type type);

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy