kotlin serialization library which came with 1.2 -...
# announcements
o
kotlin serialization library which came with 1.2 -> Why it can't serialize plain maps/lists? Or what I miss? I want to have fat map and do serialization of it back and forth... and map type is <String, Any> so Any would be backed by my @Serializable annotation
e
It should. Can you, please, shared details in #C7A1U5PTM
s
Reifed type inference is not so advanced, so if you want to serializer generic class at root-level, you need to pass serializer to desired method explicitly
o
fun main(args: Array<String>) { val x = mapOf<String,Any>("1" to 1,"2" to "2", "3" to 5.1) println(JSON.stringify(x)) }
Can't locate companion serializer for class interface java.util.Map (
ahh ok, but I don't get it? So how can I then use the single function to serialize all my "shit" maps, dataobjects etc?
looks like I need to make "switch" and look into type I am serializing, and then call stringify with one or two parameters? Or there is " generic" saver loader?
Looking into source looks like I need to control on my own if I am serializing map, then I need to call one method and if I am serializing data class, I need to call different method... Not good
It then looks like better solution is for me to create dummy "Container" data class, which I can simply have one parameter "payload" and by assigning this payload drop it into string...
s
Well, this is the price you pay to eliminate runtime instrospection and reflection. In future, we plan to add compiler support for auto-inference serializers on call site; however, the type of object is still have to be statically available (not Any)