Moshi ignore field in Kotlin

heisen picture heisen · Nov 18, 2017 · Viewed 8.1k times · Source

I want to know how to ignore a Kotlin class field when using Moshi.

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;

But I can't find the right way to get this done in Kotlin.

Answer

marstran picture marstran · Nov 18, 2017

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