Moshi 1.9.1 Cannot serialize Kotlin type

The other option if you don't want to add @JsonClass annotations all over the place is to add KotlinJsonAdapterFactory to the Moshi Builder.

val moshi = Moshi.Builder()
    .addLast(KotlinJsonAdapterFactory())
    .build()

This uses reflection and you need to add a dependency to com.squareup.moshi:moshi-kotlin as explained here https://github.com/square/moshi#kotlin


You need to add @JsonClass(generateAdapter = true) before your data class

@JsonClass(generateAdapter = true) 
data class Spot(
    var id: String = "",
    var localizedName: String? = null,
    var type: String = "",
    var location: Location? = null
)