java - 如何反序列化未知类的对象

标签 java json serialization

我需要打印序列化 Java 对象的内容(例如,从缓存中检索到的 java.io.Serializable POJO),但事先不知道其类。

更具体地说,我不需要使用经典的 ObjectInputStream 实例化一个新对象,我只需要获得一个简单的人类可读的对象表示(最好是 JSON),而不需要在类路径中加载它的类。

换句话说,我需要在不重新实现 ObjectInputStream 的情况下将 byte[](原始序列化对象)转换为 JSON 字符串。

最佳答案

这个看起来很有希望:https://github.com/unsynchronized/jdeserialize 不过我还没有尝试过。

It is a full implementation of the Object Serialization Stream Protocol, as described in the Java Object Serialization Specification, chapter 6. It does not instantiate any classes described in the stream; instead, it builds up an intermediate representation of the types, instances, and values. Because of this, it can analyze streams without access to the class code that generated them.

关于java - 如何反序列化未知类的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19258433/

相关文章:

java - 如何更有效地向对象添加多个属性

PHP - 将 MySQL 表导出到 JSON 文件

c# - 如何使用 servicestack 序列化程序将默认内容类型设置为 Json

c# - 使用 BinaryFormatter 反序列化加密数据时出现问题

c# - 在 C# 中持久化异构数组

java - Tomcat 7 中的 LDAP 身份验证,如何在 server.xml 中绑定(bind) LDAP?

java - 如何从 Guava 17 替换 Guava new MapMaker().softValues().makeMap()

java - 在非法注释上退出 Jersey 初始化

json - 为什么 CLLocation 没有序列化?

javascript - 数字未正确增加