fastjson
fastjson copied to clipboard
升级至1.2.68序列化问题
升级至1.2.68 在对jsonObject 或者 JsonArray对象进行反序列时 会报错

测试demo
` public class FastjsonTest { @Test public void test() throws Exception { JSONObject jsonObject = new JSONObject(); jsonObject.put("test", "test"); byte[] bytes = toBytes(jsonObject); System.out.println(toObj(bytes));
}
/**
* 序列化
*/
public static byte[] toBytes(Serializable obj) throws IOException {
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
) {
objectOutputStream.writeObject(obj);
return byteArrayOutputStream.toByteArray();
}
}
/**
* 反序列化
*/
public Serializable toObj(byte[] bytes) throws IOException, ClassNotFoundException {
try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
) {
Object o = objectInputStream.readObject();
return (Serializable) o;
}
}
} `
我测试没问题呀