| package com.vincent.rsf.common.utils; | 
|   | 
| import lombok.extern.slf4j.Slf4j; | 
|   | 
| import java.io.*; | 
|   | 
| @Slf4j | 
| public class Serialize { | 
|   | 
|     public static byte[] serialize(Object object) { | 
|         ObjectOutputStream oos = null; | 
|         ByteArrayOutputStream baos = null; | 
|         try { | 
|             baos = new ByteArrayOutputStream(); | 
|             oos = new ObjectOutputStream(baos); | 
|             oos.writeObject(object); | 
|             return baos.toByteArray(); | 
|         } catch (Exception e) { | 
|             log.error("Serialize.serialize", e); | 
|         } | 
|         return null; | 
|     } | 
|   | 
|     public static Object unSerialize(byte[] bytes) { | 
|         ByteArrayInputStream bais = null; | 
|         try { | 
|   | 
|             bais = new ByteArrayInputStream(bytes); | 
|             ObjectInputStream ois = new ObjectInputStream(bais){ | 
|                 @Override | 
|                 protected Class<?> resolveClass(ObjectStreamClass desc) | 
|                         throws IOException, ClassNotFoundException { | 
|                     return Class.forName( desc.getName(), true, Thread.currentThread().getContextClassLoader()); | 
|                 } | 
|             }; | 
|             return ois.readObject(); | 
|         } catch (Exception e) { | 
|             log.error("Serialize.unSerialize", e); | 
|         } | 
|         return null; | 
|     } | 
|   | 
| } |