我不是Gson专家,但我认为你可以添加注释
@com.google.gson.annotations.Expose
Run Code Online (Sandbox Code Playgroud)
或者,你可以打电话
GsonBuilder.excludeFieldsWithModifiers(int... modifiers)
Run Code Online (Sandbox Code Playgroud)
并忽略了瞬态旗帜.在此doc中搜索"Java Modifier Excleusion"(或transient)
然而,正如戴夫和路易斯评论的那样,序列化瞬态场是不寻常的.