optionId | scastieLink | codeTitle | description |
---|---|---|---|
json-codec |
Encode and decode custom data types to JSON |
The pluggable derivation system gives custom types new capabilities. |
case class Pet(
name: String,
kind: String
) derives Codec // enable coding Pet to and from text
val coco = Pet(name = "Coco", kind = "Cat")
val message = writeJson(coco)
// ^^^^^^^ contains the text: {"name":"Coco","kind":"Cat"}
readJson[Pet](message) // convert message back to a Pet!