AnyValueSerializer
Serializer that encodes Any? type using AnyValueSurrogate.
It should primarily be used to serialize values inside collection types.
usage:
// as type annotation
val customValues: MutableMap
// or directly with other serializers
val serializer = MapSerializer(String.serializer(), AnyValueSerializer)
Content copied to clipboard
example JSON output:
val myMap = mutableMapOf("hello" to "world", "foo" to null)
println(Json.encodeToString(myMap))
// >> {"hello":{"type":"java.lang.String","value":"world"},"foo":null}
Content copied to clipboard