JsonCodec

zio.blocks.schema.json.JsonCodec
See theJsonCodec companion object
abstract class JsonCodec[A] extends BinaryCodec[A]

Abstract class for encoding and decoding values of type A to and from JSON formats. Encapsulates logic to map JSON representations into native type structures and vice versa, handling serialization and deserialization as per JSON encoding standards using UTF-8 character set.

This class requires an implementation for two core operations: decoding a value of type A from a JSON representation and encoding a value of type A into a JSON representation.

Attributes

Companion
object
Source
JsonCodec.scala
Graph
Supertypes
class BinaryCodec[A]
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

def decodeValue(in: JsonReader): A

Attempts to decode a value of type A from the specified JsonReader, but may fail with JsonCodecError error if the JSON input does not encode a value of this type.

Attempts to decode a value of type A from the specified JsonReader, but may fail with JsonCodecError error if the JSON input does not encode a value of this type.

Value parameters

in

an instance of JsonReader that provides access to the JSON input to parse a JSON value to value of type A

Attributes

Source
JsonCodec.scala
def encodeValue(x: A, out: JsonWriter): Unit

Encodes the specified value using provided JsonWriter, but may fail with JsonCodecError if it cannot be encoded properly according to RFC-8259 requirements.

Encodes the specified value using provided JsonWriter, but may fail with JsonCodecError if it cannot be encoded properly according to RFC-8259 requirements.

Value parameters

out

an instance of JsonWriter that provides access to JSON output to serialize the specified value as a JSON value

x

the value provided for serialization

Attributes

Source
JsonCodec.scala

Concrete methods

override def decode(input: ByteBuffer): Either[SchemaError, A]

Decodes a value of type A from the given ByteBuffer. This method uses the default ReaderConfig to configure the decoding process. If decoding fails, a SchemaError is returned.

Decodes a value of type A from the given ByteBuffer. This method uses the default ReaderConfig to configure the decoding process. If decoding fails, a SchemaError is returned.

Value parameters

input

the ByteBuffer containing the binary data to be decoded

Attributes

Returns

Either where the Left contains a SchemaError if decoding fails, or the Right contains the successfully decoded value of type A

Definition Classes
Source
JsonCodec.scala
def decode(input: ByteBuffer, config: ReaderConfig): Either[SchemaError, A]

Decodes a value of type A from the given ByteBuffer using the specified ReaderConfig. If decoding fails, a SchemaError is returned.

Decodes a value of type A from the given ByteBuffer using the specified ReaderConfig. If decoding fails, a SchemaError is returned.

Value parameters

config

the ReaderConfig instance used to configure the decoding process

input

the ByteBuffer containing the binary data to be decoded

Attributes

Returns

Either where the Left contains a SchemaError if decoding fails, or the Right contains the successfully decoded value of type A

Source
JsonCodec.scala
def decode(input: Array[Byte]): Either[SchemaError, A]

Decodes a value of type A from the given byte array using the default ReaderConfig. If decoding fails, a SchemaError is returned.

Decodes a value of type A from the given byte array using the default ReaderConfig. If decoding fails, a SchemaError is returned.

Value parameters

input

the byte array containing the binary data to be decoded

Attributes

Returns

Either where the Left contains a SchemaError if decoding fails, or the Right contains the successfully decoded value of type A

Source
JsonCodec.scala
def decode(input: Array[Byte], from: Int, to: Int): Either[SchemaError, A]

Decodes a value of type A from the provided byte array using the specified from and to slice indices. If decoding fails, an error of type SchemaError is returned.

Decodes a value of type A from the provided byte array using the specified from and to slice indices. If decoding fails, an error of type SchemaError is returned.

Value parameters

from

the start index of the slice (inclusive)

input

the byte array containing the binary data to be decoded

to

the end index of the slice (exclusive)

Attributes

Returns

Either where the Left contains a SchemaError if decoding fails, or the Right contains the successfully decoded value of type A

Source
JsonCodec.scala
def decode(input: Array[Byte], config: ReaderConfig): Either[SchemaError, A]

Decodes a value of type A from the provided byte array using the specified ReaderConfig. If decoding fails, an error of type SchemaError is returned.

Decodes a value of type A from the provided byte array using the specified ReaderConfig. If decoding fails, an error of type SchemaError is returned.

Value parameters

config

the ReaderConfig instance used to configure the decoding process

input

the byte array containing the binary data to be decoded

Attributes

Returns

Either where the Left contains a SchemaError if decoding fails, or the Right contains the successfully decoded value of type A

Source
JsonCodec.scala
def decode(input: Array[Byte], from: Int, to: Int, config: ReaderConfig): Either[SchemaError, A]

Decodes a value of type A from the provided byte array using the specified from and to slice indices and ReaderConfig. If decoding fails, an error of type SchemaError is returned.

Decodes a value of type A from the provided byte array using the specified from and to slice indices and ReaderConfig. If decoding fails, an error of type SchemaError is returned.

Value parameters

config

the ReaderConfig instance used to configure the decoding process

from

the start index of the slice (inclusive)

input

the byte array containing the binary data to be decoded

to

the end index of the slice (exclusive)

Attributes

Returns

Either where the Left contains a SchemaError if decoding fails, or the Right contains the successfully decoded value of type A

Source
JsonCodec.scala
def decode(input: InputStream): Either[SchemaError, A]

Decodes a value of type A from the provided InputStream using the default ReaderConfig. If decoding fails, a SchemaError is returned.

Decodes a value of type A from the provided InputStream using the default ReaderConfig. If decoding fails, a SchemaError is returned.

Value parameters

input

the InputStream containing the binary data to be decoded

Attributes

Returns

Either where the Left contains a SchemaError if decoding fails, or the Right contains the successfully decoded value of type A

Source
JsonCodec.scala
def decode(input: InputStream, config: ReaderConfig): Either[SchemaError, A]

Decodes a value of type A from the provided InputStream using the specified ReaderConfig. If decoding fails, a SchemaError is returned.

Decodes a value of type A from the provided InputStream using the specified ReaderConfig. If decoding fails, a SchemaError is returned.

Value parameters

config

the ReaderConfig instance used to configure the decoding process

input

the InputStream containing the binary data to be decoded

Attributes

Returns

Either where the Left contains a SchemaError if decoding fails, or the Right contains the successfully decoded value of type A

Source
JsonCodec.scala
def decode(input: String): Either[SchemaError, A]

Decodes a value of type A from the given string using the default ReaderConfig. If decoding fails, a SchemaError is returned.

Decodes a value of type A from the given string using the default ReaderConfig. If decoding fails, a SchemaError is returned.

Value parameters

input

the string containing the data to be decoded

Attributes

Returns

Either where the Left contains a SchemaError if decoding fails, or the Right contains the successfully decoded value of type A

Source
JsonCodec.scala
def decode(input: String, config: ReaderConfig): Either[SchemaError, A]

Decodes a value of type A from the provided string using the specified ReaderConfig. If decoding fails, an error of type SchemaError is returned.

Decodes a value of type A from the provided string using the specified ReaderConfig. If decoding fails, an error of type SchemaError is returned.

Value parameters

config

the ReaderConfig instance used to configure the decoding process

input

a string containing the data to be decoded

Attributes

Returns

Either where the Left contains a SchemaError if decoding fails, or the Right contains the successfully decoded value of type A

Source
JsonCodec.scala
def decode(input: Json): Either[SchemaError, A]

Decodes a value of type A from the given Json value. If decoding fails, a SchemaError is returned.

Decodes a value of type A from the given Json value. If decoding fails, a SchemaError is returned.

Value parameters

input

the Json value containing the data to be decoded

Attributes

Returns

Either where the Left contains a SchemaError if decoding fails, or the Right contains the successfully decoded value of type A

Source
JsonCodec.scala
def decodeKey(in: JsonReader): A

Attempts to decode a value of type A from the specified JsonReader, but may fail with JsonCodecError error if the JSON input is not a key or does not encode a value of this type.

Attempts to decode a value of type A from the specified JsonReader, but may fail with JsonCodecError error if the JSON input is not a key or does not encode a value of this type.

Value parameters

in

an instance of JsonReader that provides access to the JSON input to parse a JSON key to value of type A

Attributes

Source
JsonCodec.scala
def decodeKey(s: String): A

Attempts to decode a value of type A from the string representation.

Attempts to decode a value of type A from the string representation.

Attributes

Source
JsonCodec.scala
def decodeValue(json: Json): A

Decodes a Json value into a value of type A.

Decodes a Json value into a value of type A.

Attributes

Source
JsonCodec.scala
override def encode(value: A, output: ByteBuffer): Unit

Encodes the specified value of type A into binary format and writes it to the provided ByteBuffer. This method uses the default WriterConfig for encoding configuration.

Encodes the specified value of type A into binary format and writes it to the provided ByteBuffer. This method uses the default WriterConfig for encoding configuration.

Value parameters

output

the ByteBuffer where the encoded binary data is written

value

the value of type A to be serialized into binary format

Attributes

Definition Classes
Source
JsonCodec.scala
def encode(value: A, output: ByteBuffer, config: WriterConfig): Unit

Encodes the specified value of type A into binary format and writes it to the provided ByteBuffer using the specified WriterConfig for encoding configuration.

Encodes the specified value of type A into binary format and writes it to the provided ByteBuffer using the specified WriterConfig for encoding configuration.

Value parameters

config

the WriterConfig instance used to configure the encoding process

output

the ByteBuffer where the encoded binary data is written

value

the value of type A to be serialized into binary format

Attributes

Source
JsonCodec.scala
def encode(value: A): Array[Byte]

Encodes the specified value of type A into a binary format using the default WriterConfig.

Encodes the specified value of type A into a binary format using the default WriterConfig.

Value parameters

value

the value of type A to be serialized into binary format

Attributes

Returns

an array of bytes representing the binary-encoded data

Source
JsonCodec.scala
def encode(value: A, config: WriterConfig): Array[Byte]

Encodes the specified value of type A into a binary format using the provided WriterConfig.

Encodes the specified value of type A into a binary format using the provided WriterConfig.

Value parameters

config

the WriterConfig instance used to configure the encoding process

value

the value of type A to be serialized into binary format

Attributes

Returns

an array of bytes representing the binary-encoded data

Source
JsonCodec.scala
def encode(value: A, output: OutputStream): Unit

Encodes the specified value of type A into a binary format and writes it to the provided OutputStream. This method uses the default WriterConfig for encoding configuration.

Encodes the specified value of type A into a binary format and writes it to the provided OutputStream. This method uses the default WriterConfig for encoding configuration.

Value parameters

output

the OutputStream where the encoded binary data is written

value

the value of type A to be serialized into binary format

Attributes

Source
JsonCodec.scala
def encode(value: A, output: OutputStream, config: WriterConfig): Unit

Encodes the specified value of type A into a binary format and writes it to the given OutputStream using the provided WriterConfig for encoding configuration.

Encodes the specified value of type A into a binary format and writes it to the given OutputStream using the provided WriterConfig for encoding configuration.

Value parameters

config

the WriterConfig instance used to configure the encoding process

output

the OutputStream where the encoded binary data is written

value

the value of type A to be serialized into binary format

Attributes

Source
JsonCodec.scala
def encodeKey(x: A, out: JsonWriter): Unit

Encodes the specified value using provided JsonWriter as a JSON key, but may fail with JsonCodecError if it cannot be encoded properly, according to RFC-8259 requirements.

Encodes the specified value using provided JsonWriter as a JSON key, but may fail with JsonCodecError if it cannot be encoded properly, according to RFC-8259 requirements.

Value parameters

out

an instance of JsonWriter that provides access to JSON output to serialize the specified value as a JSON key

x

the value provided for serialization

Attributes

Source
JsonCodec.scala
def encodeKey(x: A): String

Converts a value to its string representation for use as a JSON key.

Converts a value to its string representation for use as a JSON key.

Attributes

Source
JsonCodec.scala
def encodeToJson(value: A): Json

Encodes the specified value of type A into a Json value.

Encodes the specified value of type A into a Json value.

Value parameters

value

the value of type A to be serialized into Json value

Attributes

Returns

a Json value representing the encoded data

Source
JsonCodec.scala
def encodeToString(value: A): String

Encodes the specified value of type A into a string using the default WriterConfig.

Encodes the specified value of type A into a string using the default WriterConfig.

Value parameters

value

the value of type A to be serialized into a string

Attributes

Returns

a string representing the encoded data

Source
JsonCodec.scala
def encodeToString(value: A, config: WriterConfig): String

Encodes the specified value of type A into a string using the provided WriterConfig.

Encodes the specified value of type A into a string using the provided WriterConfig.

Value parameters

config

the WriterConfig instance used to configure the encoding process

value

the value of type A to be serialized into a string

Attributes

Returns

a string representing the encoded data

Source
JsonCodec.scala
def encodeValue(x: A): Json

Encodes a value of type A into a Json value.

Encodes a value of type A into a Json value.

Attributes

Source
JsonCodec.scala
def error(span: Node, error: Throwable): Nothing

Throws a JsonCodecError wrapping the given error and adding a span.

Throws a JsonCodecError wrapping the given error and adding a span.

Value parameters

error

the error to wrap

span

the span to add to the error

Attributes

Throws
Source
JsonCodec.scala
def error(span1: Node, span2: Node, error: Throwable): Nothing

Throws a JsonCodecError wrapping the given error and adding two spans.

Throws a JsonCodecError wrapping the given error and adding two spans.

Value parameters

error

the error to wrap

span1

the first span to add to the error

span2

the second span to add to the error

Attributes

Throws
Source
JsonCodec.scala
def error(spans: List[Node], error: Throwable): Nothing

Throws a JsonCodecError wrapping the given error and adding spans.

Throws a JsonCodecError wrapping the given error and adding spans.

Value parameters

error

the error to wrap

spans

spans to add to the error

Attributes

Throws
Source
JsonCodec.scala
def error(message: String): Nothing

Throws a JsonCodecError with the given error message.

Throws a JsonCodecError with the given error message.

Value parameters

message

the error message

Attributes

Throws
Source
JsonCodec.scala

Returns the JSON Schema describing values this codec encodes/decodes.

Returns the JSON Schema describing values this codec encodes/decodes.

Attributes

Source
JsonCodec.scala