我想使用 Gson 为 String 创建一个匿名对象。
我的对象不为空,但方法“toJson”返回空。
我该如何解决这个问题?
最佳答案
来自users guide :
Gson can also deserialize static nested classes. However, Gson can not automatically deserialize the pure inner classes since their no-args constructor also need a reference to the containing Object which is not available at the time of deserialization.
Gson 不进行序列化并返回 null。您可以使用静态嵌套类而不是匿名内部类。
关于java - annonymus 对象上的 Gson "toJson"返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22741268/