DiscriminatorKind

zio.blocks.schema.json.DiscriminatorKind
See theDiscriminatorKind companion trait

Attributes

Companion
trait
Source
DiscriminatorKind.scala
Graph
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type

Members list

Type members

Classlikes

case class Field(name: String) extends DiscriminatorKind

Represents a discriminator strategy where a specific field in the JSON object is used to identify the subtype of a sealed hierarchy, e.g. {"type": "SubtypeIdentifier", ...}

Represents a discriminator strategy where a specific field in the JSON object is used to identify the subtype of a sealed hierarchy, e.g. {"type": "SubtypeIdentifier", ...}

Can be used only for serializing sealed hierarchy subtypes of non-abstract classes only (not union types).

Beware that parsing may be too slow for deeply nested or recursive data structures when the discriminator field is placed at the end of the JSON object.

Don't use it for untrusted input that should be parsed to deeply nested or recursive data structures to avoid potential security vulnerabilities of DoS/DoW attacks.

Value parameters

name

The name of the discriminator field to be added to the JSON object. This field value will contain the subtype identifier as its value.

Attributes

Source
DiscriminatorKind.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case object Key extends DiscriminatorKind

Represents a discriminator strategy where the subtype identifier is encoded as the key of a JSON object.

Represents a discriminator strategy where the subtype identifier is encoded as the key of a JSON object.

It is a default strategy for serializing and deserializing of all kinds of variants (sealed hierarchies, union types, etc.).

In this strategy, the serialized representation of the subtype wraps the encoded value in a JSON object keyed by the subtype's discriminator, e.g., {"SubtypeIdentifier": {...}}.

This approach enables subtype differentiation based solely on the key of the JSON object for the sealed hierarchy.

Attributes

Source
DiscriminatorKind.scala
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Self type
Key.type
case object None extends DiscriminatorKind

Represents the absence of a discriminator strategy for serializing and deserializing sealed hierarchy subtypes or union types.

Represents the absence of a discriminator strategy for serializing and deserializing sealed hierarchy subtypes or union types.

When this strategy is used, subtype differentiation is performed without adding any explicit discriminator field or key to the serialized JSON. Instead, deserialization attempts to match the input JSON data sequentially against all possible subtypes of the sealed hierarchy until a successful match is found.

This approach relies on the order and structure of subtype definitions and may result in parsing errors if no matching subtype is found.

Beware that this strategy hides error messages of underlying parsing errors and parsing be too slow for large hierarchies of subtypes or deeply nested or recursive data structures.

Don't use it for untrusted input that should be parsed into deeply nested or recursive data structures to avoid potential security vulnerabilities of DoS/DoW attacks.

Attributes

Source
DiscriminatorKind.scala
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Self type
None.type

Inherited and Abstract types

type MirroredElemLabels <: Tuple

The names of the product elements.

The names of the product elements.

Attributes

Inherited from:
Mirror
Source
Mirror.scala
type MirroredLabel <: String

The name of the type.

The name of the type.

Attributes

Inherited from:
Mirror
Source
Mirror.scala