# TypedSerializer

open class TypedSerializer < T : Any >(kClass: KClass < T >, presetSerializers: Map < String , KSerializer<out T >> = emptyMap()) : KSerializer< T > (source)

A serializer that includes type information in the serialized output. This allows polymorphic serialization where the exact type is preserved in the output as a "type" field alongside the "value" field.

The serialized format is: `{"type": "TypeName", "value": {...}}`

#### Parameters

kClass

The Kotlin class of the base type

presetSerializers

A map of type names to their serializers for known subtypes

#### Type Parameters

T

The base type that this serializer handles

## Constructors

TypedSerializer
Link copied to clipboard
constructor(kClass: KClass < T >, presetSerializers: Map < String , KSerializer<out T >> = emptyMap())

## Properties

descriptor
Link copied to clipboard
open override val descriptor : SerialDescriptor

## Functions

deserialize
Link copied to clipboard
open override fun deserialize (decoder: Decoder): T
exclude
Link copied to clipboard
open fun exclude (type: String )

Removes a type from this serializer by its name.

include
Link copied to clipboard
open fun < O : T > include (type: String , serializer: KSerializer< O >)

Adds a new type to this serializer with its associated serializer.

mapDeserialization
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

mapFullSerialization
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

mapSerialization
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

minusAssign
Link copied to clipboard
@InternalSerializationApi
operator fun < T : Any > TypedSerializer < T >. minusAssign (kClass: KClass < T >)

Removes a type from this TypedSerializer using its class name.

plusAssign
Link copied to clipboard
@InternalSerializationApi
operator fun < T : Any > TypedSerializer < T >. plusAssign (kClass: KClass < T >)

Adds a type to this TypedSerializer using its class name as the type identifier.

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