Last active
September 19, 2018 05:23
-
-
Save sbaus42/1d77e1e5f80543e6d9b9b2d4a04e877e to your computer and use it in GitHub Desktop.
Case class decoding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.circe.generic.auto._ | |
import io.circe.syntax._ | |
import io.circe._ | |
case class Person(name: String) | |
case class Greeting(salutation: String, person: Person, eclamationMarks: Int) | |
case class Fucker(state: Map[String, List[String]]) | |
case class Foo(value: String) | |
Greeting("Hey", Person("Chris"), 3).asJson | |
val x = "string" | |
println(x) | |
//implicit val fuckerKeyEncoder: KeyEncoder[Fucker] = new KeyEncoder[Fucker] { | |
// | |
//} | |
implicit val fooKeyEncoder: KeyEncoder[Foo] = new KeyEncoder[Foo] { | |
override def apply(foo: Foo): String = foo.value | |
} | |
Fucker(Map("aaaaattttrrrr" -> List("stuff", "things"), "attr" -> List("mmm", "dddd"))).asJson | |
val stateJson = Json.obj("state" -> | |
Json.obj("random_atr" -> | |
Json.arr(Json.fromString("Something"), Json.fromString(("something else"))), | |
"another_attr" -> Json.arr(Json.fromString("Something more")) | |
)) | |
stateJson.asJson | |
//implicit val fuckerKeyDecoder: KeyDecoder[Fucker] = new KeyDecoder[Fucker] { | |
// override def apply(state: List[Map[String, List[String]]]): Option[Fucker] = Some(Fucker(state)) | |
//} | |
stateJson.as[Map[String, Map[String, List[String]]]] | |
stateJson.as[Fucker] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment