lkakarctic.blogg.se

Data class serializable kotlin
Data class serializable kotlin












These are responsible for defining how the actual serialization and deserialization of an object work. KSerializer governs the serialization and deserialization process for an object by defining strategies for serialization and deserialization - SerializationStrategy & DeserializationStrategy. This generated class implements an interface called GeneratedSerializer, which in-turn implements the KSerializer interface and overrides a number of methods. The $serializer class is what contains all the logic for the serialization process. If we look closely, the constructor is used during deserialization of data to create the class object, in our case a User object. Now, as this constructor is hidden, it must be used internally in the same class. The role of the constructor is to initialise the properties of the data class.

data class serializable kotlin

a nested static class $serializer, also deprecated and inaccessible.a synthetic, deprecated and inaccessible constructor.This code is generated by the annotation, and mainly includes If you’ve ever inspected or played around with generated code for data classes before, you’d notice some similar code along with quite a lot of extra code.

data class serializable kotlin

Some of the content has been removed from the gist for improving readability.














Data class serializable kotlin