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