https://kotlinlang.org logo
Title
a

Ankit Dubey

06/24/2021, 7:02 AM
Hi, while calling ktor API, if my query is of different type, I’m getting below exception java.lang.IllegalStateException: Serializing collections of different element types is not yet supported. Selected serializers: [kotlin.String, kotlin.Int]
val query = hashMapOf<String,Any>(
    KEY_OTP to otp.toInt(),
    KEY_MOBILE to phone
)
This is what I’ve posted However I achieved the excepted result by sending a model class as
@Serializable
data class OTPRequest(
    val mobile : String,
    val otp : Int
)
But I was wondering, It’ll be a extra burden if I’m going to create multiple request classes Any solution will be helpful. thanks
r

rnett

06/24/2021, 9:04 PM
You should be able to use
JsonObject
from kotlinx serialization.
a

Ankit Dubey

06/25/2021, 7:15 AM
Yes that worked Thanks