Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当使用 Moshi 反序列化一个类时,它在by lazy属性上失败并出现错误:
by lazy
IllegalArgumentException: No JsonAdapter for interface kotlin.Lazy annotated []
所以我想告诉 Moshi 忽略这个属性。忽略这一点的方法显然是使用@Transient但只能用于字段 - 而不是属性。
@Transient
那么在使用 Moshi 反序列化时如何忽略 Kotlin 惰性属性呢?
您可以注释委托本身:
class Foo { @delegate:Transient val bar by lazy { true } }