I'm new to using Moshi and Kotlin. I was excited to see that you have the ability to fail when you hit unexpected json.
The thing is, it doesn't seem to work for me.
Here is my builder for Retrofit
@Provides
internal fun provideBuilder(gson: Gson): Retrofit.Builder {
return Retrofit.Builder() .baseUrl(baseUrl)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(MoshiMigrationConverter(MoshiConverterFactory.create()
.failOnUnknown()))
.addConverterFactory(GsonConverterFactory.create(gson))
}
My retrofit response object looks like so in Kotlin:
data class GetAllResponse(
val id: String = "",
val imageUrl: String = "",
val title: String = "",
val description: String = "")
but then I change val description: String = "" to val banana: String = ""
everything seems to work fine instead of failing.
Is this not what failOnUnknown should catch?