Json

@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class Json(val codecName: String = automatic, val codecPackageName: String = automatic, val codecVisibility: Json.CodecVisibility = CodecVisibility.internal, val decoding: Json.Decoding = Decoding.automatic, val encoding: Json.Encoding = Encoding.automatic, val representation: Json.Representation = Representation.automatic)

Creates a JsonCodec for the annotated class.

Note that there are several limitations which classes can be annotated:

  • it and all enclosing classes must have internal or public visibility

  • it must not be abstract, sealed or inner

  • it must not be generic

Types

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class CodecProvider(val externalTypes: Array<Json.ExternalType> = [])

Creates an object implementing the annotated interface which in turn extends JsonCodecProvider and no other interfaces. That object can be accessed using JsonCodecProvider.Companion.generated. It provides all codecs which have been generated using @Json annotations. The annotated interface also specifies the JsonCodingContext type being used by all generated codecs.

Link copied to clipboard

Visibility of a created codec

Link copied to clipboard
object Companion
Link copied to clipboard
annotation class Constructor

The annotated constructor of a class annotated with @Json will be used for decoding instances of the class as JSON even if @Json.decoding would exclude them by default or if there would be multiple constructors and a decision needs to be made. This does not apply if @Json.decoding is set to none in which case an error will be raised.

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.FUNCTION])
annotation class CustomProperties

By annotating an extension function with this annotation additional code can be executed as part of the encoding of a @Json-annotated class.

Link copied to clipboard

The way in which the annotation processor can decode and instantiate a @Json-annotated class.

Link copied to clipboard

The way in which the annotation processor can encode a @Json-annotated class.

Link copied to clipboard

In a class annotated with @Json

Link copied to clipboard
@Target(allowedTargets = [])
annotation class ExternalType(val target: KClass<*>, val configuration: Json = Json(), val targetName: String = "")

Creates a JsonCodec for a class which is not part of the same module and which thus cannot be annotated with @Json.

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.PROPERTY])
annotation class Property(val serializedName: String = automatic)

Annotated properties of a class annotated with @Json will be used for encoding instances of the class as JSON even if @Json.encoding would exclude them by default. This does not apply if @Json.encoding is set to none in which case an error will be raised.

Link copied to clipboard

The way in which the annotation processor will represent a @Json-annotated class in JSON.

Properties

Link copied to clipboard

Name of the generated codec class.

Link copied to clipboard

Package name of the generated codec class.

Link copied to clipboard

Visibility of the generated codec class.

Link copied to clipboard

Defines how to create an instance of the annotated class when decoding it from JSON.

Link copied to clipboard

Defines how an instance of the annotated class will be encoded to JSON.

Link copied to clipboard

Defines how the annotated class is represented in JSON.