kluck
10/16/2020, 1:59 PMJsonDecodingException: Polymorphic serializer was not found for class discriminator [...]
. I don't know exactly where I'm supposed to have retrofit handle this serializer: should it be inside my Json
config when declaring my ConverterFactory
? Here is some of my code to make it more clear what I'm currently doing:
object DecodedBarcodeSerializer : JsonContentPolymorphicSerializer<DecodedBarcode>(DecodedBarcode::class) { ... } // here's my serializer for a sealed class DecodedBarcode.
// In tests
Json.decodeFromString(DecodedBarcodeSerializer, stringified) // -> tests work just fine when specifically calling the serializer
// api
interface DecoderApi { // --> I tried using a `@file:UseSerializers(DecodedBarcodeSerializer::class)` but retrofit doesn't care about it :p
@POST("$BASE/decoder/decoded-barcodes/decode")
fun decodeBarcode(@Body barcode: String): IO<DecodedBarcode>
}
// retrofit declaration
val contentType = "application/json".toMediaType()
Retrofit.Builder()
.baseUrl(instance<String>(BASE_URL))
.client(instance())
.addCallAdapterFactory(IOAdapterFactory())
.addConverterFactory(Json {
ignoreUnknownKeys = true
isLenient = true
prettyPrint = true // --> should I put something like a SerializersModule here?
}.asConverterFactory(contentType))
.build()