Folks, where are the instructions for use and/or extension of the MapLikeSerializer and HashMapSerializer classes?
s
serebit
01/29/2019, 4:03 PM
You can use them by extension properties like so:
(String.serializer() to Int.serializer()).map
produces a KSerializer for a Map<String, Int>.
h
hallvard
01/30/2019, 12:05 PM
Thanks
hallvard
01/30/2019, 12:18 PM
But I am still not fully familiar with this. What I try to serialize and deserialize is a map of Strings to {primitives and a small selection of serializable data class objects}. I have the possibility to have all the data classes be sealed, so a serializer could think of them as one, and I know that no other unknown object will suddenly appear in the map. But how would I go about making a serializer for a map where the values are either one of these data classes or a primitive? Are we in the not-(hopfully-yet)-feasible field here?
s
serebit
01/30/2019, 3:35 PM
This is something I’ve pondered myself, and unfortunately there isn’t a clean solution to this. You could use PolymorphicDeserializer (which is experimental last I checked), or write your own implementation, or write a wrapper function that checks the JsonObject first to see what type the value is before deserializing it.