我正在尝试使用 gson 从反序列化中排除 Kotlin 属性。我尝试了不同的方法来注释属性 @Transient
创建自定义注释策略(当然在 gson 构建器中指定策略),但似乎没有任何效果,因为该属性一直为 null 而不是我初始化该属性的值。
我没有尝试使用 @Expose
注释,但我不想用 @Expose
注释其他字段
拜托,我怎样才能使用 gson + Kotlin 实现这一目标?
最佳答案
@Transient 为我工作。
@Transient lateinit var bar: SomeCustomType
根据@Transient 定义:
Marks the JVM backing field of the annotated property as
transient
, meaning that it is not part of the default serialized form of the object.
关于kotlin - 使用 gson 从序列化/反序列化中排除 Kotlin 数据类属性/字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53425600/