package moe.nea.firmament.util import java.util.SortedMap import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.MapSerializer import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder class SortedMapSerializer, V>(val keyDelegate: KSerializer, val valueDelegate: KSerializer) : KSerializer> { val mapSerializer = MapSerializer(keyDelegate, valueDelegate) override val descriptor: SerialDescriptor get() = mapSerializer.descriptor override fun deserialize(decoder: Decoder): SortedMap { return (mapSerializer.deserialize(decoder).toSortedMap(Comparator.naturalOrder())) } override fun serialize(encoder: Encoder, value: SortedMap) { mapSerializer.serialize(encoder, value) } }