org.sigilaris.core.codec.json
Members list
Packages
Type members
Classlikes
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 Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Source
- JsonConfig.scala
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
DiscriminatorConfig.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 unchangedSnakeCase- Convert to snake_caseKebabCase- Convert to kebab-caseCamelCase- Convert to camelCase
Attributes
- Note
-
Naming policies are applied bidirectionally to both encoding and decoding.
- Source
- JsonConfig.scala
- Supertypes
-
trait Enumtrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
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 Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Source
- JsonCodec.scala
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
JsonCodec.type
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 Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Source
- JsonConfig.scala
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
JsonConfig.type
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 Objecttrait Matchableclass Any
- Self type
-
JsonDecoder[A]
Attributes
- Companion
- trait
- Source
- JsonDecoder.scala
- Supertypes
- Self type
-
JsonDecoder.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 Objecttrait Matchableclass Any
- Known subtypes
-
class Decodersobject JsonDecoder
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 Objecttrait Matchableclass Any
- Self type
-
JsonEncoder[A]
Attributes
- Companion
- trait
- Source
- JsonEncoder.scala
- Supertypes
- Self type
-
JsonEncoder.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 Objecttrait Matchableclass Any
- Known subtypes
-
class Encodersobject JsonEncoder
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 Objecttrait Matchableclass Any
- Known subtypes
- Self type
-
JsonKeyCodec[K]
Attributes
- Companion
- trait
- Source
- JsonKeyCodec.scala
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
JsonKeyCodec.type
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 Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Companion object for JsonSubtypeLabels.
Companion object for JsonSubtypeLabels.
Attributes
- Companion
- class
- Source
- JsonSubtypeLabels.scala
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
JsonSubtypeLabels.type
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 nullJBool: JSON booleanJNumber: JSON number (stored as BigDecimal for precision)JString: JSON stringJArray: JSON arrayJObject: JSON object (field map)
Attributes
- Companion
- object
- Source
- JsonValue.scala
- Supertypes
-
trait Enumtrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- enum
- Source
- JsonValue.scala
- Supertypes
-
trait Sumtrait Mirrorclass Objecttrait Matchableclass 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 Enumtrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all