有没有办法序列化一个类的 transient 字段?文档中提到默认情况下不支持它,但可能有办法打开它?
非常感谢
最佳答案
我不是Gson专家,但我认为你可以添加注解
@com.google.gson.annotations.Expose
javadocs here - note that you have to do a few other things too
或者,你可以调用
GsonBuilder.excludeFieldsWithModifiers(int... modifiers)
并省略 transient 标志。在 this doc 中搜索“Java 修饰符排除”(或 transient )
但是,正如 Dave 和 Louis 评论的那样,序列化 transient 字段是不寻常的。
关于java - Gson:序列化 transient 字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10919081/