Folks, I create a new Serializer for a Primitive t...
# serialization
s
Folks, I create a new Serializer for a Primitive type( String ), when I use it in the String type, works perfectly, but with List<String> does not. Its given me this exception:
Caused by: java.lang.ClassCastException: kotlin.collections.EmptyList cannot be cast to java.lang.String
How can I make my Serializer works in List and Map? My currently serializer.
Copy code
@Serializer(forClass = String::class)
object ChangeColor : KSerializer<String> { ... }
Usage that is causing this exception:
Copy code
@Serializable(with = ChangeColor::class)
val messages: List<String> = listOf()
d
Try doing,
Copy code
val messages: List<@Serializable(with = ChangeColor::class) String> = listOf()
s
Not working.
But, is not getting any exception. But the parsing not work.
d
How does it not work? The String isn't being transformed or..?
s
Yes, is not beeing transformed
I will run some logging to check this more precisely.
@Dominaezzz Sorry, was my bad here. Tkx for helping, I does not know that I could you directly at the type of the List.
d
Glad I could help.