JsonCodec

org.sigilaris.core.codec.json.JsonCodec
See theJsonCodec companion object
final case class JsonCodec[A](encoder: JsonEncoder[A], decoder: JsonDecoder[A])

Bidirectional JSON codec bundling a JsonEncoder and a JsonDecoder.

Provides convenience encode/decode that delegate to the underlying instances. When both encoder and decoder are available, a given codec is derived automatically.

'''Example:'''

case class User(name: String, age: Int) derives JsonCodec
val codec = JsonCodec[User]
val json  = codec.encode(User("Alice", 30))
val user  = codec.decode(json)

See also: JsonEncoder for encoding only, JsonDecoder for decoding only

Value parameters

decoder

the JSON decoder for type A

encoder

the JSON encoder for type A

Attributes

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

Members list

Value members

Concrete methods

def decode(json: JsonValue): Either[DecodeFailure, A]

Decodes a JSON value using the bundled decoder.

Decodes a JSON value using the bundled decoder.

Value parameters

json

the JSON value to decode

Attributes

Returns

either a decode failure or the decoded value

Source
JsonCodec.scala
def encode(value: A): JsonValue

Encodes a value using the bundled encoder.

Encodes a value using the bundled encoder.

Value parameters

value

the value to encode

Attributes

Returns

the JSON representation

Source
JsonCodec.scala

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product