Hey all. I'm trying to use this data class and get...
# serialization
s
Hey all. I'm trying to use this data class and getting this response:
j.b.u: Can't locate argument-less serializer for class e.b.b.d.a (Kotlin reflection is not available). For generic classes, such as lists, please provide serializer explicitly.
Can anyone confirm that this means I have to write my own serializer because it's using a
Map
? Or is there a way to do this that I'm missing somewhere? I'm using this with a Ktor request.
d
That's weird. You shouldn't need a custom serializer.
It should just work.
This is for json right?
s
Yeah
just setting up Ktor like so:
Copy code
install(JsonFeature) {
    serializer = KotlinxSerializer()
}
I have another request class I am using that involves an Array. Should that just work out of box as well?
Copy code
@Serializable
data class Request(
    val flags: Array<String>,
    val userInfo: UserAttributes
)
UserAttributes:
Copy code
@Serializable
data class UserAttributes(
    val booleanAttributes: Map<String, Boolean>,
    val numberAttributes: Map<String, Float>,
    val stringAttributes: Map<String, String>
)
Not quite sure from the error message which data class is having the problem unfortunately, I think it's getting eaten by ProGuard
d
Yes the Array one should work as well.
Maybe proguard is the issue?
s
The issue I was having is that Ktor wasn't using the generated
serializer()
from Kotlinx.Serialization, and was instead trying to use reflection to find it but could not. I set it explicitly with
setMapper(KClass, KSerializer)
and it is now working, though I do wonder why Ktor does not find the KSerializer without me explicitly setting it seeing as it is always generated when something is annotated with
@serialized
.. 🤔