/**
* 序列化
*
* @param params
* @return
* @throws IOException
*/
public String serialize(Object... params) {
String serializeString = null;
if (null != params && params.length > 0) {
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(params);
serializeString = byteArrayOutputStream.toString("ISO-8859-1");
serializeString = URLEncoder.encode(serializeString, "UTF-8");
objectOutputStream.close();
byteArrayOutputStream.close();
} catch (Exception e) {
System.out.println(e+"对象序列化异常1");
}
}
return serializeString;
}
/**
* 反序列化
*
* @param serializeString
* @return
* @throws IOException
* @throws ClassNotFoundException
*/
public Object reserialize(String serializeString) {
Object obj = null;
if (null != serializeString) {
try {
serializeString = URLDecoder.decode(serializeString, "UTF-8");
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
serializeString.getBytes("ISO-8859-1"));
ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
obj = objectInputStream.readObject();
objectInputStream.close();
byteArrayInputStream.close();
} catch (Exception e) {
System.out.println(e+"对象反序列化异常2");
}
}
return obj;
}
注意序列化的类不能使内部类