Package-level declarations
Basic core concepts and annotations that set up serialization process.
Basic core concepts and annotations that set up serialization process.
Types
SerialFormat that allows conversions to and from ByteArray via encodeToByteArray and decodeFromByteArray methods.
Instructs the plugin to use ContextualSerializer on a given property or type. Context serializer is usually used when serializer for type can only be found in runtime. It is also possible to apply ContextualSerializer to every property of the given type, using file-level UseContextualSerialization annotation.
This class provides support for retrieving a serializer in runtime, instead of using the one precompiled by the serialization plugin. This serializer is enabled by Contextual or UseContextualSerialization.
Deserialization strategy defines the serial form of a type T, including its structural description, declared by the descriptor and the actual deserialization process, defined by the implementation of the deserialize method.
Controls whether the target property is serialized when its value is equal to a default value, regardless of the format settings. Does not affect decoding and deserialization process.
Marks declarations that are still experimental in kotlinx.serialization, which means that the design of the corresponding declarations has open issues which may (or may not) lead to their changes in the future. Roughly speaking, there is a chance that those declarations will be deprecated in the near future or the semantics of their behavior may change in some way that may break some code.
Meta-annotation that commands the compiler plugin to handle the annotation as serialization-specific. Serialization-specific annotations are preserved in the SerialDescriptor and can be retrieved during serialization process with SerialDescriptor.getElementAnnotations.
Public API marked with this annotation is effectively internal, which means it should not be used outside of kotlinx.serialization
. Signature, semantics, source and binary compatibilities are not guaranteed for this API and will be changed without any warnings or migration aids. If you cannot avoid using internal API to solve your problem, please report your use-case to serialization's issue tracker.
Instructs the serialization plugin to keep automatically generated implementation of KSerializer for the current class if a custom serializer is specified at the same time @Serializable(with=SomeSerializer::class)
.
KSerializer is responsible for the representation of a serial form of a type T in terms of encoders and decoders and for constructing and deconstructing T from/to a sequence of encoding primitives. For classes marked with @Serializable, can be obtained from generated companion extension .serializer()
or from serializer
The meta-annotation for adding Serializable behaviour to user-defined annotations.
Thrown when KSerializer did not receive a non-optional property from CompositeDecoder and CompositeDecoder.decodeElementIndex had already returned CompositeDecoder.DECODE_DONE.
Instructs the serialization plugin to use PolymorphicSerializer on an annotated property or type usage. When used on class, replaces its serializer with PolymorphicSerializer everywhere.
Indicates that property must be present during deserialization process, despite having a default value.
Represents an instance of a serialization format that can interact with KSerializer and is a supertype of all entry points for a serialization. It does not impose any restrictions on a serialized form or underlying storage, neither it exposes them.
Meta-annotation that commands the compiler plugin to handle the annotation as serialization-specific. Serialization-specific annotations are preserved in the SerialDescriptor and can be retrieved during serialization process with SerialDescriptor.getElementAnnotations for properties annotations and SerialDescriptor.annotations for class annotations.
The main entry point to the serialization process. Applying Serializable to the Kotlin class instructs the serialization plugin to automatically generate implementation of KSerializer for the current class, that can be used to serialize and deserialize the class. The generated serializer can be accessed with T.serializer()
extension function on the class companion, both are generated by the plugin as well.
A generic exception indicating the problem in serialization or deserialization process.
Serialization strategy defines the serial form of a type T, including its structural description, declared by the descriptor and the actual serialization process, defined by the implementation of the serialize method.
Instructs the serialization plugin to turn this class into serializer for specified class forClass. However, it would not be used automatically. To apply it on particular class or property, use Serializable or UseSerializers, or Contextual with runtime registration.
Overrides the name of a class or a property in the corresponding SerialDescriptor. Names and serial names are used by text-based serial formats in order to encode the name of the class or the name of the property, e.g. by Json
.
SerialFormat that allows conversions to and from String via encodeToString and decodeFromString methods.
Marks this property invisible for the whole serialization process, including serial descriptors. Transient properties must have default values.
Instructs the plugin to use ContextualSerializer for every type in the current file that is listed in the forClasses.
Adds serializerClasses to serializers resolving process inside the plugin. Each of serializerClasses must implement KSerializer.
Functions
Decodes and deserializes the given byte array to the value of type T using deserializer retrieved from the reified type parameter.
Decodes byte array from the given hex string and the decodes and deserializes it to the value of type T, delegating it to the BinaryFormat.
Serializes and encodes the given value to byte array using serializer retrieved from the reified type parameter.
Serializes and encodes the given value to byte array, delegating it to the BinaryFormat, and then encodes resulting bytes to hex string.
Serializes and encodes the given value to string using serializer retrieved from the reified type parameter.
Retrieves a serializer for the given type T. This overload is a reified version of serializer(KType)
.
Retrieves serializer for the given kClass. This method uses platform-specific reflection available.
Reflectively retrieves a serializer for the given type.
Retrieves a KSerializer for the given KClass. The given class must be annotated with Serializable or be one of the built-in types.
Retrieves default serializer for the given type T and, if T is not serializable, fallbacks to contextual lookup.
Retrieves default serializer for the given type and, if type is not serializable, fallbacks to contextual lookup. type argument is usually obtained with typeOf method.
Retrieves serializer for the given kClass and, if kClass is not serializable, fallbacks to contextual lookup. This method uses platform-specific reflection available.
Retrieves a serializer for the given type using reflective construction and contextual lookup as a fallback for non-serializable types.
Reflectively retrieves a serializer for the given type.
Retrieves a KSerializer for the given KClass or returns null
if none is found. The given class must be annotated with Serializable or be one of the built-in types. This method uses platform-specific reflection available for the given erased KClass
and it is not recommended to use this method for anything, but last-ditch resort, e.g. when all type info is lost, your application has crashed and it is the final attempt to log or send some serializable data.
Retrieves default serializer for the given type and, if type is not serializable, fallbacks to contextual lookup. type argument is usually obtained with typeOf method.
Retrieves a serializer for the given type using reflective construction and contextual lookup as a fallback for non-serializable types.