org.sigilaris.core.codec.json

Members list

Type members

Classlikes

final case class DiscriminatorConfig(typeNameStrategy: TypeNameStrategy)

Discriminator configuration for coproducts (wrapped-by-type-key form).

Discriminator configuration for coproducts (wrapped-by-type-key form).

Value parameters

typeNameStrategy

how to project canonical subtype labels to JSON keys

Attributes

Example
 val config = DiscriminatorConfig(TypeNameStrategy.SimpleName)
 // Encodes: sealed trait Color; case object Red extends Color
 //   → { "Red": {} }
Companion
object
Source
JsonConfig.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Source
JsonConfig.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type

Field naming policies applied during product derivation.

Field naming policies applied during product derivation.

Controls how Scala field names are transformed in JSON encoding/decoding.

Available policies:

  • Identity - Keep field names unchanged
  • SnakeCase - Convert to snake_case
  • KebabCase - Convert to kebab-case
  • CamelCase - Convert to camelCase

Attributes

Note

Naming policies are applied bidirectionally to both encoding and decoding.

Source
JsonConfig.scala
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class JsonCodec[A](encoder: JsonEncoder[A], decoder: JsonDecoder[A])

Bidirectional JSON codec bundling a JsonEncoder and a JsonDecoder.

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
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object JsonCodec

Attributes

Companion
class
Source
JsonCodec.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
JsonCodec.type
final case class JsonConfig(fieldNaming: FieldNamingPolicy, dropNullValues: Boolean, treatAbsentAsNull: Boolean, writeBigIntAsString: Boolean, writeBigDecimalAsString: Boolean, discriminator: DiscriminatorConfig)

JSON configuration affecting encode/decode behaviors.

JSON configuration affecting encode/decode behaviors.

Controls all aspects of JSON encoding and decoding, including field naming, null handling, number formatting, and discriminator strategy.

Value parameters

discriminator

configuration for coproduct type discrimination

dropNullValues

if true, null values are omitted from encoded objects

fieldNaming

how to transform field names

treatAbsentAsNull

if true, missing fields decode as null (for Option)

writeBigDecimalAsString

if true, BigDecimal is encoded as JSON string

writeBigIntAsString

if true, BigInt is encoded as JSON string

Attributes

Example
 val customConfig = JsonConfig.default.copy(
   fieldNaming = FieldNamingPolicy.SnakeCase,
   dropNullValues = false,
 )
Companion
object
Source
JsonConfig.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object JsonConfig

Attributes

Companion
class
Source
JsonConfig.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
JsonConfig.type
trait JsonDecoder[A]

Type class for decoding the core JsonValue AST into Scala values.

Type class for decoding the core JsonValue AST into Scala values.

Decoders use JsonConfig to interpret field naming, discriminator strategy, null/absent semantics, and big number representations.

Combinators map/emap help build validated or dependent decoders; derived provides automatic derivation for products and sums.

Attributes

See also

JsonEncoder for the inverse operation

JsonCodec for bidirectional encoding and decoding

JsonConfig for configuration options

Note

Decoding validates structure and types. Failures return org.sigilaris.core.failure.DecodeFailure with descriptive error messages.

Example
 case class User(name: String, age: Int) derives JsonDecoder
 val json = JsonValue.obj("name" -> JString("Alice"), "age" -> JNumber(30))
 val user = JsonDecoder[User].decode(json)
Companion
object
Source
JsonDecoder.scala
Supertypes
class Object
trait Matchable
class Any
Self type

Attributes

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

Shared provider of JSON decoder instances parameterized by JsonConfig.

Shared provider of JSON decoder instances parameterized by JsonConfig.

Subclassed by JsonDecoder (default config) and JsonDecoder.configured.Decoders (custom config).

Attributes

Source
JsonDecoder.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Decoders
object JsonDecoder
trait JsonEncoder[A]

Type class for encoding Scala values into the core JsonValue AST.

Type class for encoding Scala values into the core JsonValue AST.

Encoders consult a JsonConfig to honor naming policies, null/absent handling, discriminator strategy, and number formatting for big numbers.

Use contramap to adapt existing encoders and derived to auto-derive for products and sums when appropriate givens are in scope.

Attributes

See also

JsonDecoder for the inverse operation

JsonCodec for bidirectional encoding and decoding

JsonConfig for configuration options

Note

Encoding is deterministic: the same value always produces the same JSON structure. However, object field order may vary. Use sorted encoding if field order matters.

Example
 case class User(name: String, age: Int) derives JsonEncoder
 val user = User("Alice", 30)
 val json = JsonEncoder[User].encode(user)
Companion
object
Source
JsonEncoder.scala
Supertypes
class Object
trait Matchable
class Any
Self type

Attributes

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

Shared provider of JSON encoder instances parameterized by JsonConfig.

Shared provider of JSON encoder instances parameterized by JsonConfig.

Subclassed by JsonEncoder (default config) and JsonEncoder.configured.Encoders (custom config).

Attributes

Source
JsonEncoder.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Encoders
object JsonEncoder
trait JsonKeyCodec[K]

Typeclass for encoding/decoding map keys to/from JSON object field names.

Typeclass for encoding/decoding map keys to/from JSON object field names.

JSON objects require string keys. This typeclass bridges between typed Scala map keys and JSON string field names.

Base instances are provided for common types:

  • String (identity)
  • Numeric types (Int, Long, Double, BigInt, BigDecimal)
  • UUID

Attributes

See also
Note

Field naming policies from JsonConfig are NOT applied to map keys. Keys are encoded/decoded using only the JsonKeyCodec instance.

Example
 val m    = Map(1 -> "one", 2 -> "two")
 val json = JsonEncoder[Map[Int, String]].encode(m)
 // json: JObject(Map("1" -> JString("one"), "2" -> JString("two")))
Companion
object
Source
JsonKeyCodec.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object bigDecimalKey
object bigIntKey
object doubleKey
object intKey
object longKey
object stringKey
object uuidKey
Show all
Self type
object JsonKeyCodec

Attributes

Companion
trait
Source
JsonKeyCodec.scala
Supertypes
class Object
trait Matchable
class Any
Self type
final case class JsonSubtypeLabels

Shared subtype-label mapping for wrapped-by-type-key JSON coproducts.

Shared subtype-label mapping for wrapped-by-type-key JSON coproducts.

Sealed traits and enums both derive their canonical labels from Scala 3 Mirror labels. Discriminator configuration only projects those canonical labels onto JSON keys; it does not introduce a second independent wire format.

Value parameters

canonical

the canonical Mirror labels for each subtype

encoded

the projected JSON keys for each subtype

Attributes

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

Companion object for JsonSubtypeLabels.

Companion object for JsonSubtypeLabels.

Attributes

Companion
class
Source
JsonSubtypeLabels.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
enum JsonValue

Minimal, library-agnostic JSON value ADT.

Minimal, library-agnostic JSON value ADT.

This AST is deliberately small and independent of any backend. All higher-level behaviors (naming policies, discriminator, null/absent, etc.) are handled by encoders/decoders and derivation, not by this ADT.

The six cases cover all JSON types:

  • JNull: JSON null
  • JBool: JSON boolean
  • JNumber: JSON number (stored as BigDecimal for precision)
  • JString: JSON string
  • JArray: JSON array
  • JObject: JSON object (field map)

Attributes

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

Attributes

Companion
enum
Source
JsonValue.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
JsonValue.type

Strategy for representing subtype names in coproduct discriminator.

Strategy for representing subtype names in coproduct discriminator.

Used in the wrapped-by-type-key encoding: { "SubtypeName": { ... } }. The starting point is always the canonical Scala 3 Mirror label shared by sealed traits and enums.

Attributes

Source
JsonConfig.scala
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all