Gre*_*nis 3 android kotlin moshi
当使用 Moshi 反序列化一个类时,它在by lazy属性上失败并出现错误:
IllegalArgumentException: No JsonAdapter for interface kotlin.Lazy annotated []
Run Code Online (Sandbox Code Playgroud)
所以我想告诉Moshi忽略这个属性。忽略这一点的方法显然是使用@Transient但是只能在字段上使用 - 而不是属性。
那么在使用 Moshi 反序列化时如何忽略 Kotlin 惰性属性呢?
您可以注释委托本身:
class Foo {
@delegate:Transient
val bar by lazy { true }
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
727 次 |
| 最近记录: |