circelib
package circelib
- Alphabetic
- Public
- Protected
Value Members
- object ADTSection extends AnyFlatSpec with Matchers with Section
The most straightforward way to encode / decode ADTs is by using generic derivation for the case classes but explicitly defined instances for the ADT type.
ADTs encoding and decoding
The most straightforward way to encode / decode ADTs is by using generic derivation for the case classes but explicitly defined instances for the ADT type.
- object CirceLibrary extends Library
circe (pronounced SUR-see, or KEER-kee in classical Greek) is a JSON library for Scala (and Scala.js).
- object CustomCodecsSection extends AnyFlatSpec with Matchers with Section
If you want to write your own codec instead of using automatic or semi-automatic derivation, you can do so in a couple of ways.
Custom encoders/decoders
If you want to write your own codec instead of using automatic or semi-automatic derivation, you can do so in a couple of ways.
Firstly, you can write a new
Encoder[A]
andDecoder[A]
from scratchclass Thing() implicit val encodeFoo: Encoder[Thing] = new Encoder[Thing] { final def apply(a: Thing): Json = ??? // your implementation goes here } implicit val decodeFoo: Decoder[Thing] = new Decoder[Thing] { final def apply(c: HCursor): Decoder.Result[Thing] = Left(DecodingFailure("Not implemented yet", c.history)) }
But in many cases you might find it more convenient to piggyback on top of the decoders that are already available. For example, a codec for
java.time.Instant
might look like this:import cats.syntax.either._ import java.time.Instant implicit val encodeInstant: Encoder[Instant] = Encoder.encodeString.contramap[Instant](_.toString) implicit val decodeInstant: Decoder[Instant] = Decoder.decodeString.emap { str => Either.catchNonFatal(Instant.parse(str)).leftMap(t => "Instant") }
- object EncodingDecodingSection extends AnyFlatSpec with Matchers with Section
- object JsonSection extends AnyFlatSpec with Matchers with Section
- object OpticsSection extends AnyFlatSpec with Matchers with Section
- object TraversingSection extends AnyFlatSpec with Matchers with Section