Moshi ignore field in Kotlin
Use the @Transient
annotation.
@Transient
private val your_variable_name: String
Doc here: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-transient/index.html
Kotlin + Retrofit + Moshi
In case where you want to conditionally ignore fields, you can set it to null.
data class User(var id: String, var name: string?)
val user = User()
user.id = "some id"
user.name = null
The Json generated would be
user{
"id": "some id"
}