Package kotlinx.serialization.builtins

Serializers for standard Kotlin types, like Int, String, List, etc.

Types

LongAsStringSerializer
Link copied to clipboard
common

Serializer that encodes and decodes Long as its string representation.

Intended to be used for interoperability with external clients (mainly JavaScript ones), where numbers can't be parsed correctly if they exceed abs(2^53-1).

object LongAsStringSerializer : KSerializer<Long>

Functions

ArraySerializer
Link copied to clipboard
common

Returns serializer for reference Array of type E with descriptor of StructureKind.LIST kind. Each element of the array is serialized with the given elementSerializer.

inline fun <T : Any, E : T?> ArraySerializer(elementSerializer: KSerializer<E>): KSerializer<Array<E>>
fun <T : Any, E : T?> ArraySerializer(kClass: KClass<T>, elementSerializer: KSerializer<E>): KSerializer<Array<E>>
BooleanArraySerializer
Link copied to clipboard
common

Returns serializer for BooleanArray with descriptor of StructureKind.LIST kind. Each element of the array is serialized one by one with Boolean.Companion.serializer.

fun BooleanArraySerializer(): KSerializer<BooleanArray>
ByteArraySerializer
Link copied to clipboard
common

Returns serializer for ByteArray with descriptor of StructureKind.LIST kind. Each element of the array is serialized one by one with Byte.Companion.serializer.

fun ByteArraySerializer(): KSerializer<ByteArray>
CharArraySerializer
Link copied to clipboard
common

Returns serializer for CharArray with descriptor of StructureKind.LIST kind. Each element of the array is serialized one by one with Char.Companion.serializer.

fun CharArraySerializer(): KSerializer<CharArray>
DoubleArraySerializer
Link copied to clipboard
common

Returns serializer for DoubleArray with descriptor of StructureKind.LIST kind. Each element of the array is serialized one by one with Double.Companion.serializer.

fun DoubleArraySerializer(): KSerializer<DoubleArray>
FloatArraySerializer
Link copied to clipboard
common

Returns serializer for FloatArray with descriptor of StructureKind.LIST kind. Each element of the array is serialized one by one with Float.Companion.serializer.

fun FloatArraySerializer(): KSerializer<FloatArray>
IntArraySerializer
Link copied to clipboard
common

Returns serializer for IntArray with descriptor of StructureKind.LIST kind. Each element of the array is serialized one by one with Int.Companion.serializer.

fun IntArraySerializer(): KSerializer<IntArray>
ListSerializer
Link copied to clipboard
common

Creates a serializer for List<T> for the given serializer of type T.

fun <T> ListSerializer(elementSerializer: KSerializer<T>): KSerializer<List<T>>
LongArraySerializer
Link copied to clipboard
common

Returns serializer for LongArray with descriptor of StructureKind.LIST kind. Each element of the array is serialized one by one with Long.Companion.serializer.

fun LongArraySerializer(): KSerializer<LongArray>
MapEntrySerializer
Link copied to clipboard
common

Returns built-in serializer for Map.Entry. Resulting serializer represents entry as a structure with a single key-value pair. E.g. Pair(1, 2) and Map.Entry(1, 2) will be serialized to JSON as {"first": 1, "second": 2} and {"1": 2} respectively.

fun <K, V> MapEntrySerializer(keySerializer: KSerializer<K>, valueSerializer: KSerializer<V>): KSerializer<Map.Entry<K, V>>
MapSerializer
Link copied to clipboard
common

Creates a serializer for Map<K, V> for the given serializers for its ket type K and value type V.

fun <K, V> MapSerializer(keySerializer: KSerializer<K>, valueSerializer: KSerializer<V>): KSerializer<Map<K, V>>
PairSerializer
Link copied to clipboard
common

Returns built-in serializer for Kotlin Pair. Resulting serializer represents pair as a structure of two key-value pairs.

fun <K, V> PairSerializer(keySerializer: KSerializer<K>, valueSerializer: KSerializer<V>): KSerializer<Pair<K, V>>
serializer
Link copied to clipboard
common

Returns serializer for Boolean with descriptor of PrimitiveKind.BOOLEAN kind.

fun Boolean.Companion.serializer(): KSerializer<Boolean>

Returns serializer for Byte with descriptor of PrimitiveKind.BYTE kind.

fun Byte.Companion.serializer(): KSerializer<Byte>

Returns serializer for Char with descriptor of PrimitiveKind.CHAR kind.

fun Char.Companion.serializer(): KSerializer<Char>

Returns serializer for Double with descriptor of PrimitiveKind.DOUBLE kind.

fun Double.Companion.serializer(): KSerializer<Double>

Returns serializer for Float with descriptor of PrimitiveKind.FLOAT kind.

fun Float.Companion.serializer(): KSerializer<Float>

Returns serializer for Int with descriptor of PrimitiveKind.INT kind.

fun Int.Companion.serializer(): KSerializer<Int>

Returns serializer for Long with descriptor of PrimitiveKind.LONG kind.

fun Long.Companion.serializer(): KSerializer<Long>

Returns serializer for Short with descriptor of PrimitiveKind.SHORT kind.

fun Short.Companion.serializer(): KSerializer<Short>

Returns serializer for String with descriptor of PrimitiveKind.STRING kind.

fun String.Companion.serializer(): KSerializer<String>

Returns serializer for UByte.

@ExperimentalUnsignedTypes()
fun UByte.Companion.serializer(): KSerializer<UByte>

Returns serializer for UInt.

@ExperimentalUnsignedTypes()
fun UInt.Companion.serializer(): KSerializer<UInt>

Returns serializer for ULong.

@ExperimentalUnsignedTypes()
fun ULong.Companion.serializer(): KSerializer<ULong>

Returns serializer for UShort.

@ExperimentalUnsignedTypes()
fun UShort.Companion.serializer(): KSerializer<UShort>

Returns serializer for Unit with descriptor of StructureKind.OBJECT kind.

fun Unit.serializer(): KSerializer<Unit>
SetSerializer
Link copied to clipboard
common

Creates a serializer for Set<T> for the given serializer of type T.

fun <T> SetSerializer(elementSerializer: KSerializer<T>): KSerializer<Set<T>>
ShortArraySerializer
Link copied to clipboard
common

Returns serializer for ShortArray with descriptor of StructureKind.LIST kind. Each element of the array is serialized one by one with Short.Companion.serializer.

fun ShortArraySerializer(): KSerializer<ShortArray>
TripleSerializer
Link copied to clipboard
common

Returns built-in serializer for Kotlin Triple. Resulting serializer represents triple as a structure of three key-value pairs.

fun <A, B, C> TripleSerializer(aSerializer: KSerializer<A>, bSerializer: KSerializer<B>, cSerializer: KSerializer<C>): KSerializer<Triple<A, B, C>>

Properties

nullable
Link copied to clipboard
common

Returns a nullable serializer for the given serializer of non-null type.

val <T : Any> KSerializer<T>.nullable: KSerializer<T?>