我想知道在使用Moshi时如何忽略Kotlin类字段.

I've found this answer for Java (Moshi ignore field), that indicates to use the keyword transient as follows

private transient String your_variable_name;

但我在Kotlin 找不到正确的方法.

推荐答案

使用@Transient注释.

@Transient
private val your_variable_name: String

这里的文档:https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-transient/index.html

Kotlin相关问答推荐

Kotlin中函数引用的否定

如何在Docker中使用Selenium和chromedriver?

为什么记得不将 StateFlow 转换为特定类型?

在子类中覆盖 kotlin 运算符扩展函数

compareBy 如何使用布尔表达式在 kotlin 中工作

Kotlin 中列表或数组的乘积

具有多个不同类型来源的 LiveData

Swift vs Kotlin 在排序数组上的表现

如何创建 Kotlin DSL - DSL 语法 Kotlin

retrofit 响应代码 405 并带有消息method not allowed here

无法解决:androidx.lifecycle:lifecycle-viewmodel-ktx:1.1.1

取消信号上的kotlin流量采集

Kotlin suspend fun

如何在使用 Gradle 的 AppEngine 项目中使用 Kotlin

Kotlin 的 Double.toInt() 中使用了哪种方法,舍入还是截断?

在Kotlin中使用@Service时引发异常

内联 onFocusChange kotlin

Recyclerview: listen to padding click events

项目不会使用 Kotlin 1.1.3 构建

如何在 IntelliJ IDEA 中禁用粘贴时将 Java 转换为 Kotlin?