Import Org.slf4j.logger;import org.slf4j.loggerfactory;import Sun.misc.base64decoder;import Sun.misc.BASE64Encoder ; Import Java.io.bytearrayinputstream;import Java.io.bytearrayoutputstream;import Java.io.ioexception;import Java.io.objectinputstream;import java.io.objectoutputstream;/** * Serialization Tool class */public class Serializeutil {private final S Tatic Logger Logger = Loggerfactory.getlogger (Serializeutil.class); public static String Serialize (Object object) {bytearrayoutputstream bos = new Bytearrayoutputstream (); ObjectOutputStream oos = null; try {oos = new ObjectOutputStream (BOS); Oos.writeobject (object); Oos.flush (); return new Base64encoder (). Encode (Bos.tobytearray ()); }catch (IOException e) {logger.error ("serialization error", E); }finally {try {if (Oos! = null) {oos.close (); } bos.close (); } catch (IOException e) { E.printstacktrace (); }} return null; public static object Unserialize (String object) {Bytearrayinputstream bis = null; ObjectInputStream ois = null; try {bis = new Bytearrayinputstream (new Base64decoder (). Decodebuffer (object)); OIS = new ObjectInputStream (bis); Object o = Ois.readobject (); return o; } catch (IOException e) {logger.error ("Deserialization error: IO exception", e); } catch (ClassNotFoundException e) {logger.error ("deserialization Error: Class not found", e); }finally {try {if (bis!=null) {bis.close (); } if (Ois!=null) {ois.close (); }} catch (IOException e) {e.printstacktrace (); }} return null; }}
Java Serialization Tool Class