JsoniterPrism

dev.constructive.eo.jsoniter.JsoniterPrism
See theJsoniterPrism companion class
object JsoniterPrism

Attributes

Companion
class
Source
JsoniterPrism.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Grouped members

Optics

def apply[A](using JsonValueCodec[A]): JsoniterPrism[A]

Root-level Prism from a JSON byte buffer to a native type A — a Prism[Array[Byte], A]: to decodes the WHOLE document via the codec (Miss when it doesn't decode as A), from / JsoniterPrism.reverseGet encode via writeToArray. At the root the full-cover Prism laws hold (up to canonical re-encoding). Drill from here with .field: JsoniterPrism[Person].field(_.age).

Root-level Prism from a JSON byte buffer to a native type A — a Prism[Array[Byte], A]: to decodes the WHOLE document via the codec (Miss when it doesn't decode as A), from / JsoniterPrism.reverseGet encode via writeToArray. At the root the full-cover Prism laws hold (up to canonical re-encoding). Drill from here with .field: JsoniterPrism[Person].field(_.age).

Attributes

Source
JsoniterPrism.scala

Constructors

def fromPath[A](path: String)(using codec: JsonValueCodec[A]): Either[String, JsoniterPrism[A]]

Build a read-write Prism over a JSON byte buffer at the given JSONPath — the ONLY string-path constructor, and it keeps the failure in the type. An unparseable path, or one carrying a [*] wildcard (a JsoniterTraversal shape), comes back as Left(message): a path is DATA (a config value, a CLI argument, a registry lookup), so there is no throwing twin to reach for. Path syntax: $, dotted field names ($.foo.bar), array indices ($[0]). See PathParser for the full grammar; apply is the path-free root constructor.

Build a read-write Prism over a JSON byte buffer at the given JSONPath — the ONLY string-path constructor, and it keeps the failure in the type. An unparseable path, or one carrying a [*] wildcard (a JsoniterTraversal shape), comes back as Left(message): a path is DATA (a config value, a CLI argument, a registry lookup), so there is no throwing twin to reach for. Path syntax: $, dotted field names ($.foo.bar), array indices ($[0]). See PathParser for the full grammar; apply is the path-free root constructor.

Attributes

Example
import com.github.plokhotnyuk.jsoniter_scala.macros.JsonCodecMaker
given codec: JsonValueCodec[Long] = JsonCodecMaker.make
val idP: Either[String, JsoniterPrism[Long]] =
 JsoniterPrism.fromPath[Long]("$.payload.user.id")
val bytes: Array[Byte] = ...
idP.map(_.foldMap(identity)(bytes))   // Either[String, Long], no AST allocation
Source
JsoniterPrism.scala

Extensions

Extensions

extension [A](o: JsoniterPrism[A])
transparent inline def field[B](inline selector: A => B)(using codecB: JsonValueCodec[B]): JsoniterPrism[B]

.field(_.x) — drill via selector lambda, compile-time checked against A's case fields.

.field(_.x) — drill via selector lambda, compile-time checked against A's case fields.

Attributes

Source
JsoniterPrism.scala
extension [A](o: JsoniterPrism[A])
transparent inline def at(i: Int): Any

.at(i) — drill into the i-th array element.

.at(i) — drill into the i-th array element.

Attributes

Source
JsoniterPrism.scala
extension [A](o: JsoniterPrism[A])
transparent inline def each: Any

.each — split into a JsoniterTraversal over the iterated array.

.each — split into a JsoniterTraversal over the iterated array.

Attributes

Source
JsoniterPrism.scala