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
Overrides the type class instance at an exact path in the schema tree identified by optic. This is the most precise override: it targets one specific location.
Overrides the type class instance at an exact path in the schema tree identified by optic. This is the most precise override: it targets one specific location.
Overrides the type class instance for every occurrence of the type identified by typeId, regardless of where it appears in the schema tree. This is the least precise override.
Overrides the type class instance for every occurrence of the type identified by typeId, regardless of where it appears in the schema tree. This is the least precise override.
Overrides the type class instance for a term (record field or variant case) identified by termName inside a parent record or variant identified by typeId. This is a medium-precision override between optic-based (exact path) and type-based (all occurrences).
Overrides the type class instance for a term (record field or variant case) identified by termName inside a parent record or variant identified by typeId. This is a medium-precision override between optic-based (exact path) and type-based (all occurrences).
The typeId refers to the parent record/variant type, not the field type. The field type B is not statically checked against the actual term type. If no term with the given name exists in the parent type, the override is silently ignored.
Adds a modifier at an exact path in the schema tree identified by optic. Accepts both Modifier.Reflect (applied to the node itself) and Modifier.Term (applied to the terminal field or case at the end of the optic path).
Adds a modifier at an exact path in the schema tree identified by optic. Accepts both Modifier.Reflect (applied to the node itself) and Modifier.Term (applied to the terminal field or case at the end of the optic path).
Adds a term-level modifier for a field or variant case identified by termName inside a parent type identified by typeId. The typeId refers to the parent record/variant type that owns the term, not the term's own type. If no term with the given name exists in the parent type, the modifier is silently ignored.
Adds a term-level modifier for a field or variant case identified by termName inside a parent type identified by typeId. The typeId refers to the parent record/variant type that owns the term, not the term's own type. If no term with the given name exists in the parent type, the modifier is silently ignored.