CborSerializable

@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class CborSerializable(val typeKey: String = "", val typeId: String = "", val schemaHash: String = "", val schemaId: String = "")

Marks class for automatic CBOR serialization code generation.

CBOR serializer uses a CBOR map that maps Kotlin field names to serialized field values.

Fields with value null are not written to the serialized map.

The following field types are allowed:

  • primitive: Int, Long, Float, Double, String, Boolean

  • time: Instant and LocalDate

  • binary: ByteString and ByteArray

  • CBOR generic value: DataItem

  • enums

  • types manually implementing CBOR serialization (annotated by CborSerializationImplemented)

  • types with automatically generated CBOR serialization (annotated by CborSerializable)

  • maps, lists, or sets of the above (sets are treated as lists)

  • nullable variants of the above

Single-level sealed class hierarchies are supported. Annotation is required only on the root class of the sealed hierarchy. A special key ("type" by default, see typeKey) is added to CBOR map to indicate the actual value type (type id). It is recommended that leaf class names include base class name either as a prefix or a suffix. Type id is generated from the leaf class name, stripping base class name if possible or can be specified explicitly by typeId.

Properties

Link copied to clipboard

Optional parameter that identifies the schema of the serialized CBOR representation for the objects of the annotated type.

Link copied to clipboard

Optional parameter that identifies this type in the serialized CBOR representation in objects that contain the fields of the annotated type.

Link copied to clipboard

Optional parameter for sealed class hierarchies to define the type id for this class.

Link copied to clipboard

Optional parameter for sealed class hierarchies to define the key that carries type id.