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
def fromPath[A](path: String)(using codec: JsonValueCodec[A]): JsoniterPrism[A]

Build a read-write Prism over a JSON byte buffer at the given JSONPath.

Build a read-write Prism over a JSON byte buffer at the given JSONPath.

Throws IllegalArgumentException if the path string is not parseable. Path syntax: $, dotted field names ($.foo.bar), array indices ($[0]). See PathParser for the full grammar.

Attributes

Example
import com.github.plokhotnyuk.jsoniter_scala.macros.JsonCodecMaker
given codec: JsonValueCodec[Long] = JsonCodecMaker.make
val idP = JsoniterPrism.fromPath[Long]("$.payload.user.id")
val bytes: Array[Byte] = ...
idP.foldMap(identity)(bytes)  // 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