0

I am using Kotlinx Serialization with Retrofit and try to send params at Body via HashMap like below

@POST("post")
suspend fun sendPost(@Body params : HasMap<String, @Contextual @RawValue Any>) : GenericResponse<Post>

But it gives this error message

Unable to create @Body converter for java.util.HashMap<java.lang.String, java.lang.Object> (parameter #1)

I also add SerializersModule to Retrofit but it did not help

fun provideRetrofit(baseUrl : String, okHttpClient: OkHttpClient) : Retrofit {
    val contentType = "application/json".toMediaType()
    val json = Json {
        serializersModule = SerializersModule {
            contextual(String.serializer())
            contextual(Int.serializer())
            contextual(Double.serializer())
            contextual(Boolean.serializer())
        }
    }
    return Retrofit.Builder()
        .baseUrl(baseUrl)
        .client(okHttpClient)
        .addConverterFactory(json.asConverterFactory(contentType))
        .build()
}

Anyone can help?

Kotlinx Version 1.0.1

Kotlinx Converter Version 0.8.0

Kotlin Version 1.4.10
4

1 回答 1

0

According to this issue we are not able to do this

于 2020-11-02T07:31:17.353 回答