// Path: ddth-commons-core/src/main/java/com/github/ddth/commons/serialization/DeserializationException.java
// public class DeserializationException extends SerDeserException {
// 
//     private static final long serialVersionUID = 1L;
// 
//     public DeserializationException() {
//     }
// 
//     public DeserializationException(String message) {
//         super(message);
//     }
// 
//     public DeserializationException(Throwable cause) {
//         super(cause);
//     }
// 
//     public DeserializationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public DeserializationException(String message, Throwable cause, boolean enableSuppression,
//             boolean writableStackTrace) {
//         super(message, cause, enableSuppression, writableStackTrace);
//     }
// 
// }
// 
// Path: ddth-commons-core/src/main/java/com/github/ddth/commons/serialization/ISerializationSupport.java
// public interface ISerializationSupport {
//     /**
//      * Serializes this object to {@code byte[]}.
//      * 
//      * @return
//      * @throws SerializationException
//      */
//     public byte[] toBytes() throws SerializationException;
// 
//     /**
//      * Deserializes and populates this object.
//      * 
//      * @param data
//      * @return
//      * @throws DeserializationException
//      */
//     public ISerializationSupport fromBytes(byte[] data) throws DeserializationException;
// }
// 
// Path: ddth-commons-core/src/main/java/com/github/ddth/commons/serialization/SerializationException.java
// public class SerializationException extends SerDeserException {
// 
//     private static final long serialVersionUID = 1L;
// 
//     public SerializationException() {
//     }
// 
//     public SerializationException(String message) {
//         super(message);
//     }
// 
//     public SerializationException(Throwable cause) {
//         super(cause);
//     }
// 
//     public SerializationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public SerializationException(String message, Throwable cause, boolean enableSuppression,
//             boolean writableStackTrace) {
//         super(message, cause, enableSuppression, writableStackTrace);
//     }
// 
// }


import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.Reader;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.ObjectPool;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.nustaq.serialization.FSTConfiguration;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.esotericsoftware.kryo.util.Pool;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.NullNode;
import com.github.ddth.commons.serialization.DeserializationException;
import com.github.ddth.commons.serialization.ISerializationSupport;
import com.github.ddth.commons.serialization.SerializationException;
     * If the target class implements {@link ISerializationSupport}, this method
     * calls its {@link ISerializationSupport#toBytes()} method; otherwise FST
     * library is used to serialize the object.
     * </p>
     * 
     * @param data
     * @param clazz
     * @param classLoader
     * @return
     * @deprecated since 0.9.2 with no replacement, use
     *             {@link #fromByteArrayFst(byte[], Class, ClassLoader)} or
     *             {@link #fromByteArrayKryo(byte[], Class, ClassLoader)}
     */
    public static <T> T fromByteArray(byte[] data, Class<T> clazz, ClassLoader classLoader) {
        if (data == null) {
            return null;
        }
        if (ReflectionUtils.hasInterface(clazz, ISerializationSupport.class)) {
            ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
            if (classLoader != null) {
                Thread.currentThread().setContextClassLoader(classLoader);
            }
            try {
                Constructor<T> constructor = clazz.getDeclaredConstructor();
                constructor.setAccessible(true);
                T obj = constructor.newInstance();
                ((ISerializationSupport) obj).fromBytes(data);
                return obj;
            } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
                    | SecurityException | IllegalArgumentException | InvocationTargetException e) {
// Path: ddth-commons-core/src/main/java/com/github/ddth/commons/serialization/DeserializationException.java
// public class DeserializationException extends SerDeserException {
// 
//     private static final long serialVersionUID = 1L;
// 
//     public DeserializationException() {
//     }
// 
//     public DeserializationException(String message) {
//         super(message);
//     }
// 
//     public DeserializationException(Throwable cause) {
//         super(cause);
//     }
// 
//     public DeserializationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public DeserializationException(String message, Throwable cause, boolean enableSuppression,
//             boolean writableStackTrace) {
//         super(message, cause, enableSuppression, writableStackTrace);
//     }
// 
// }
// 
// Path: ddth-commons-core/src/main/java/com/github/ddth/commons/serialization/ISerializationSupport.java
// public interface ISerializationSupport {
//     /**
//      * Serializes this object to {@code byte[]}.
//      * 
//      * @return
//      * @throws SerializationException
//      */
//     public byte[] toBytes() throws SerializationException;
// 
//     /**
//      * Deserializes and populates this object.
//      * 
//      * @param data
//      * @return
//      * @throws DeserializationException
//      */
//     public ISerializationSupport fromBytes(byte[] data) throws DeserializationException;
// }
// 
// Path: ddth-commons-core/src/main/java/com/github/ddth/commons/serialization/SerializationException.java
// public class SerializationException extends SerDeserException {
// 
//     private static final long serialVersionUID = 1L;
// 
//     public SerializationException() {
//     }
// 
//     public SerializationException(String message) {
//         super(message);
//     }
// 
//     public SerializationException(Throwable cause) {
//         super(cause);
//     }
// 
//     public SerializationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public SerializationException(String message, Throwable cause, boolean enableSuppression,
//             boolean writableStackTrace) {
//         super(message, cause, enableSuppression, writableStackTrace);
//     }
// 
// }


// Path: ddth-commons-core/src/main/java/com/github/ddth/commons/utils/SerializationUtils.java
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.Reader;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.ObjectPool;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.nustaq.serialization.FSTConfiguration;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.esotericsoftware.kryo.util.Pool;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.NullNode;
import com.github.ddth.commons.serialization.DeserializationException;
import com.github.ddth.commons.serialization.ISerializationSupport;
import com.github.ddth.commons.serialization.SerializationException;

     * If the target class implements {@link ISerializationSupport}, this method
     * calls its {@link ISerializationSupport#toBytes()} method; otherwise FST
     * library is used to serialize the object.
     * </p>
     * 
     * @param data
     * @param clazz
     * @param classLoader
     * @return
     * @deprecated since 0.9.2 with no replacement, use
     *             {@link #fromByteArrayFst(byte[], Class, ClassLoader)} or
     *             {@link #fromByteArrayKryo(byte[], Class, ClassLoader)}
     */
    public static <T> T fromByteArray(byte[] data, Class<T> clazz, ClassLoader classLoader) {
        if (data == null) {
            return null;
        }
        if (ReflectionUtils.hasInterface(clazz, ISerializationSupport.class)) {
            ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
            if (classLoader != null) {
                Thread.currentThread().setContextClassLoader(classLoader);
            }
            try {
                Constructor<T> constructor = clazz.getDeclaredConstructor();
                constructor.setAccessible(true);
                T obj = constructor.newInstance();
                ((ISerializationSupport) obj).fromBytes(data);
                return obj;
            } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
                    | SecurityException | IllegalArgumentException | InvocationTargetException e) {
                throw new DeserializationException(e);