gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 12:42:58 25 4
gpt4 key购买 nike

我想使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com