Search code examples
androidkotlinmoshi

Moshi fails on Kotlin lazy properties


When deserializing a class with Moshi it fails on by lazy property with error:

IllegalArgumentException: No JsonAdapter for interface kotlin.Lazy annotated []

So I want to tell Moshi to ignore the property. The way to ignore this is apparently to use @Transient however that can only be used on a field - not a property.

So how to ignore Kotlin lazy properties when deserializing with Moshi?


Solution

  • You can annotate the delegate itself:

    class Foo {
        @delegate:Transient
        val bar by lazy { true }
    }