java - annonymus 对象上的 Gson "toJson"返回 null

标签 java android

我想使用 Gson 为 String 创建一个匿名对象。

我的对象不为空,但方法“toJson”返回空。

enter image description here

我该如何解决这个问题?

最佳答案

来自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/

相关文章:

android - 此客户端 ID 全局唯一且已被使用

android - 如何在特定索引处获取 ListView 的 subview

java - 如何在我的界面中为最终变量创建 Java 字段注释

Java 查询错误和安全

java - 防止 hibernate 合并后刷新

android - 仅在我自己的应用程序中发送和接收 SMS,而不是在使用 native SMS API 的 android 中的 native Message 应用程序中

java - 使用 ArrayList Java 中的方法

Java Web 服务错误 : com. ctc.wstx.exc.WstxEOFException:prolog 中出现意外的 EOF

android - 从 Firebase 身份验证中检索用户列表

android - 如何在 SupportMapFragment 中使用 View 绑定(bind)?