zio.blocks.schema.derive

Members list

Type members

Classlikes

Attributes

Companion
class
Source
BindingInstance.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
final case class BindingInstance[TC[_], T, A](binding: Binding[T, A], instance: Lazy[TC[A]])

Attributes

Companion
object
Source
BindingInstance.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object Derivable

Attributes

Companion
trait
Source
Derivable.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Derivable.type
trait Derivable[-D, TC[_]]

Attributes

Companion
object
Source
Derivable.scala
Supertypes
class Object
trait Matchable
class Any
final case class DerivationBuilder[TC[_], A](schema: Schema[A], deriver: Deriver[TC], instanceOverrides: IndexedSeq[InstanceOverride], modifierOverrides: IndexedSeq[ModifierOverride])

A DerivationBuilder is capable of deriving a type class instance for any data type that has a schema. Though instances for all substructures can be derived automatically, you can also specify instances for specific substructures using the instance method, and modifiers for them using the modifier method.

A DerivationBuilder is capable of deriving a type class instance for any data type that has a schema. Though instances for all substructures can be derived automatically, you can also specify instances for specific substructures using the instance method, and modifiers for them using the modifier method.

import zio.blocks.schema.json._

case class Person(name: String, age: Int)
object Person extends CompanionOptics[Person] {
 implicit val schema: Schema[Person] = Schema.derived
 val name: Lens[Person, String] = $(_.name)
 val age: Lens[Person, Int]     = $(_.age)
}

val personCodec: JsonCodec[Person] = Person.schema
 .deriving(JsonCodecDeriver)
 .instance(Person.age, JsonCodec.intCodec)
 .modifier(Person.name, Modifier.rename("fullName"))
 .derive

Attributes

Source
DerivationBuilder.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
trait Deriver[TC[_]]

Attributes

Source
Deriver.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
Self type
Deriver[TC]
trait HasInstance[F[_, _], TC[_]]

Attributes

Source
HasInstance.scala
Supertypes
class Object
trait Matchable
class Any
trait HasInstances[F[_, _], TC[_]]

Attributes

Source
HasInstances.scala
Supertypes
class Object
trait Matchable
class Any
sealed trait InstanceOverride

An override that supplies a custom type class instance during derivation, bypassing the auto-derived one.

An override that supplies a custom type class instance during derivation, bypassing the auto-derived one.

Resolution priority (highest to lowest):

  1. InstanceOverrideByOptic — matches an exact path in the schema tree
  2. InstanceOverrideByTypeAndTermName — matches a term (field or case) name inside a specific parent record/variant
  3. InstanceOverrideByType — matches every occurrence of a type

Attributes

Source
InstanceOverride.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
case class InstanceOverrideByOptic[TC[_], A](optic: DynamicOptic, instance: Lazy[TC[A]]) extends InstanceOverride

Overrides the type class instance for the substructure at an exact path in the schema tree.

Overrides the type class instance for the substructure at an exact path in the schema tree.

This is the most precise override: it targets one specific location identified by a DynamicOptic. Created via DerivationBuilder.instance(optic, instance).

Attributes

Source
InstanceOverride.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case class InstanceOverrideByType[TC[_], A](typeId: TypeId[A], instance: Lazy[TC[A]]) extends InstanceOverride

Overrides the type class instance for every occurrence of a type, regardless of where it appears in the schema tree.

Overrides the type class instance for every occurrence of a type, regardless of where it appears in the schema tree.

This is the least precise override. Created via DerivationBuilder.instance(typeId, instance).

Attributes

Source
InstanceOverride.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case class InstanceOverrideByTypeAndTermName[TC[_], P, A](typeId: TypeId[P], termName: String, instance: Lazy[TC[A]]) extends InstanceOverride

Overrides the type class instance for a term (record field or variant case) with a specific name inside a parent record or variant identified by its TypeId. Applies at every matching (parentTypeId, termName) pair in the schema tree.

Overrides the type class instance for a term (record field or variant case) with a specific name inside a parent record or variant identified by its TypeId. Applies at every matching (parentTypeId, termName) pair in the schema tree.

This provides medium precision between InstanceOverrideByOptic and InstanceOverrideByType. Created via DerivationBuilder.instance(typeId, termName, instance).

Attributes

Source
InstanceOverride.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object Instances

Attributes

Companion
class
Source
Instances.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Instances.type
final case class Instances[TC[_], A](automatic: Lazy[TC[A]], custom: Option[Lazy[TC[A]]])

Attributes

Companion
object
Source
Instances.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
sealed trait ModifierOverride

An override that attaches a Modifier to a schema node during derivation.

An override that attaches a Modifier to a schema node during derivation.

Unlike InstanceOverride, modifier overrides are additive: when multiple overrides match the same node, their modifiers are combined (optic-matched modifiers are prepended before type-matched ones).

Attributes

Source
ModifierOverride.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Attaches a Modifier.Reflect to the schema node at an exact path in the schema tree.

Attaches a Modifier.Reflect to the schema node at an exact path in the schema tree.

Created via DerivationBuilder.modifier(optic, modifier) when the modifier is a Modifier.Reflect.

Attributes

Source
ModifierOverride.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case class ModifierReflectOverrideByType[A](typeId: TypeId[A], modifier: Reflect) extends ModifierOverride

Attaches a Modifier.Reflect to every schema node whose type matches the given TypeId.

Attaches a Modifier.Reflect to every schema node whose type matches the given TypeId.

Created via DerivationBuilder.modifier(typeId, modifier).

Attributes

Source
ModifierOverride.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case class ModifierTermOverrideByOptic[A](optic: DynamicOptic, termName: String, modifier: Term) extends ModifierOverride

Attaches a Modifier.Term to a specific term (field or case) within the schema node at an exact path. The termName identifies which field or case within the matched node receives the modifier.

Attaches a Modifier.Term to a specific term (field or case) within the schema node at an exact path. The termName identifies which field or case within the matched node receives the modifier.

Created via DerivationBuilder.modifier(optic, modifier) when the modifier is a Modifier.Term. The optic's last node is extracted as the term name, and the remaining prefix becomes the path.

Attributes

Source
ModifierOverride.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case class ModifierTermOverrideByType[A](typeId: TypeId[A], termName: String, modifier: Term) extends ModifierOverride

Attaches a Modifier.Term to a specific term (field or case) within every schema node whose type matches the given TypeId. The termName identifies which field or case within the matched node receives the modifier.

Attaches a Modifier.Term to a specific term (field or case) within every schema node whose type matches the given TypeId. The termName identifies which field or case within the matched node receives the modifier.

Attributes

Source
ModifierOverride.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all