// 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;
package com.github.ddth.commons.utils;




/**
 * Serialization helper class.
 * 
 * <ul>
 * <li>JSON serialization: use {@code com.fasterxml.jackson} library.</li>
 * <li>Binary serialization: 3 choices of API
 * <ul>
 * <li>{@code jboss-serialization} library (deprecated since v0.6.0!), or</li>
 * <li>{@code Kryo} library or</li>
 * <li>{@code FST} library</li>
 * </ul>
 * </li>
 * </ul>
 * 
 * @author Thanh Nguyen <btnguyen2k@gmail.com>
 * @since 0.2.0
 */
public class SerializationUtils {
    /*----------------------------------------------------------------------*/
    /**
     * Serialize an object to byte array.
     * 
     * <p>
     * If the target object implements {@link ISerializationSupport}, this
     * method calls its {@link ISerializationSupport#toBytes()} method;
     * otherwise FST library is used to serialize the object.
     * </p>
     * 
     * @param obj
     * @return
     * @deprecated since 0.9.2 with no replacement, use {@link #toByteArrayFst(Object)} or
     *             {@link #toByteArrayKryo(Object)}
     */
    public static byte[] toByteArray(Object obj) {
        return toByteArray(obj, null);
    }

    /**
     * Serialize an object to byte array, with a custom class loader.
     * 
     * <p>
     * If the target object implements {@link ISerializationSupport}, this
     * method calls its {@link ISerializationSupport#toBytes()} method;
     * otherwise FST library is used to serialize the object.
     * </p>
     * 
     * @param obj
     * @param classLoader
     * @return
     * @deprecated since 0.9.2 with no replacement, use {@link #toByteArrayFst(Object, ClassLoader)}
     *             or {@link #toByteArrayKryo(Object, ClassLoader)}
     */
    public static byte[] toByteArray(Object obj, ClassLoader classLoader) {
// 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;

package com.github.ddth.commons.utils;




/**
 * Serialization helper class.
 * 
 * <ul>
 * <li>JSON serialization: use {@code com.fasterxml.jackson} library.</li>
 * <li>Binary serialization: 3 choices of API
 * <ul>
 * <li>{@code jboss-serialization} library (deprecated since v0.6.0!), or</li>
 * <li>{@code Kryo} library or</li>
 * <li>{@code FST} library</li>
 * </ul>
 * </li>
 * </ul>
 * 
 * @author Thanh Nguyen <btnguyen2k@gmail.com>
 * @since 0.2.0
 */
public class SerializationUtils {
    /*----------------------------------------------------------------------*/
    /**
     * Serialize an object to byte array.
     * 
     * <p>
     * If the target object implements {@link ISerializationSupport}, this
     * method calls its {@link ISerializationSupport#toBytes()} method;
     * otherwise FST library is used to serialize the object.
     * </p>
     * 
     * @param obj
     * @return
     * @deprecated since 0.9.2 with no replacement, use {@link #toByteArrayFst(Object)} or
     *             {@link #toByteArrayKryo(Object)}
     */
    public static byte[] toByteArray(Object obj) {
        return toByteArray(obj, null);
    }

    /**
     * Serialize an object to byte array, with a custom class loader.
     * 
     * <p>
     * If the target object implements {@link ISerializationSupport}, this
     * method calls its {@link ISerializationSupport#toBytes()} method;
     * otherwise FST library is used to serialize the object.
     * </p>
     * 
     * @param obj
     * @param classLoader
     * @return
     * @deprecated since 0.9.2 with no replacement, use {@link #toByteArrayFst(Object, ClassLoader)}
     *             or {@link #toByteArrayKryo(Object, ClassLoader)}
     */
    public static byte[] toByteArray(Object obj, ClassLoader classLoader) {
        if (obj instanceof ISerializationSupport) {