0PricingLogin
Scala for Backend Engineering & Functional Programming · Lesson

Decoding into Case Classes

Map JSON onto your types.

Decoders Map JSON to Types

A Decoder[A] knows how to read a Json value into a Scala type A.

Circe provides decoders for primitives and collections out of the box, and can build decoders for your own case classes automatically.

A Target Case Class

Suppose your API returns user records. Model the shape with a case class whose field names match the JSON keys.

Matching names is what lets Circe derive a decoder with no manual wiring.

case class User(name: String, age: Int, admin: Boolean)

All lessons in this course

  1. Parsing JSON
  2. Decoding into Case Classes
  3. Encoding to JSON
  4. Custom Codecs
← Back to Scala for Backend Engineering & Functional Programming