commonMain.dk.cachet.carp.common.infrastructure.serialization.MapAsArraySerializer.kt Maven / Gradle / Ivy
Go to download
Helper classes and base types relied upon by all subsystems. This library does not contain any domain logic.
The newest version!
package dk.cachet.carp.common.infrastructure.serialization
import kotlinx.serialization.*
import kotlinx.serialization.builtins.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
/**
* Serializes a [Map] as an array of JSON objects which each have a "key" and "value"
* instead of a single JSON object containing values for all keys in the map, which is the default.
*
* This is useful when using JSON serialization and the serialized keys in a map violate JSON recommendations.
* E.g., the key may include discouraged symbols such as '.', or '$' for BSON.
*/
class MapAsArraySerializer(
private val keySerializer: KSerializer,
private val valueSerializer: KSerializer
) : KSerializer