MapperSerializer

open class MapperSerializer<I, O>(base: KSerializer<I>, serialize: (Encoder, O) -> I, deserialize: (Decoder, I) -> O) : KSerializer<O> , DeserializationStrategy<O> , SerializationStrategy<O> (source)

Use this serializer when you have serializable type I and want to map it to some O in process of serialization/deserialization

Parameters

base

Serializer for I

serialize

Will be used in serialize method to convert incoming O to I and serialize with base

deserialize

Will be used in deserialize method to convert deserialized by base to O

Constructors

Link copied to clipboard
constructor(base: KSerializer<I>, serialize: (O) -> I, deserialize: (I) -> O)
constructor(base: KSerializer<I>, serialize: (Encoder, O) -> I, deserialize: (I) -> O)
constructor(base: KSerializer<I>, serialize: (O) -> I, deserialize: (Decoder, I) -> O)
constructor(base: KSerializer<I>, serialize: (Encoder, O) -> I, deserialize: (Decoder, I) -> O)

Properties

Link copied to clipboard
open override val descriptor: SerialDescriptor

Functions

Link copied to clipboard
open override fun deserialize(decoder: Decoder): O
Link copied to clipboard
inline fun <I : Any, O> DeserializationStrategy<I>.mapDeserialization(noinline deserialize: (I) -> O): MapperDeserializationStrategy<I, O>

Will create MapperDeserializationStrategy to allow you to map I to O using deserialize lambda during deserialization process

Link copied to clipboard
inline fun <I : Any, O> KSerializer<I>.mapFullSerialization(noinline serialize: (O) -> I, noinline deserialize: (I) -> O): MapperSerializer<I, O>

Will create MapperSerializer to allow you to map O to I and vice verse using serialize/deserialize lambda during serialization/deserialization process

Link copied to clipboard
inline fun <I : Any, O> SerializationStrategy<I>.mapSerialization(noinline serialize: (O) -> I): MapperSerializationStrategy<I, O>

Will create MapperSerializationStrategy to allow you to map O to I using serialize lambda during serialization process

Link copied to clipboard
open override fun serialize(encoder: Encoder, value: O)