Skip to content

Instantly share code, notes, and snippets.

@gigiigig
Created March 31, 2016 16:04
Show Gist options
  • Save gigiigig/79d5e1360b464294f335704c24e258b3 to your computer and use it in GitHub Desktop.
Save gigiigig/79d5e1360b464294f335704c24e258b3 to your computer and use it in GitHub Desktop.
scala> sealed trait Op
defined trait Op
scala> case class Foo(s: String) extends Op
defined class Foo
scala> case class Ciao(i: Int) extends Op
defined class Ciao
scala> case class Bar(op: Op, b: Boolean)
defined class Bar
scala> Bar(Ciao(3), false)
res6: Bar = Bar(Ciao(3),false)
scala> res6.asJson
res7: io.circe.Json =
{
"op" : {
"Ciao" : {
"i" : 3
}
},
"b" : false
}
scala> decode[Bar](res7.toString)
res8: cats.data.Xor[io.circe.Error,Bar] = Right(Bar(Ciao(3),false))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment