by shigemk2

当面は技術的なことしか書かない

Fully automatic derivation circe

Fully automatic derivation

import io.circe.generic.auto._ を忘れると、could not find implicit value for parameter encoder って怒られる

  • scala 2.12.2
  • circe 0.7.0
import io.circe.generic.auto._
// import io.circe.generic.auto._

case class Person(name: String)
// defined class Person

case class Greeting(salutation: String, person: Person, exclamationMarks: Int)
// defined class Greeting

Greeting("Hey", Person("Chris"), 3).asJson
// res6: io.circe.Json =
// {
//   "salutation" : "Hey",
//   "person" : {
//     "name" : "Chris"
//   },
//   "exclamationMarks" : 3
// }