Created
January 4, 2013 15:44
-
-
Save seanparsons/4453577 to your computer and use it in GitHub Desktop.
Decode encode example with argonaut.
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
case class Person(name: String, age: Int) | |
implicit val DecodePerson: DecodeJson[Person] = jdecode2L(Person(_: String, _: Int))("name", "age") | |
implicit val EncodePerson: EncodeJson[Person] = jencode2L((p: Person) => (p.name, p.age))("name", "age") | |
val decoded: Option[Person] = """{"name":"Fred","age":"40"}""".decodeOption[Person] | |
val encoded: Option[String] = decoded.map(_.jencode.nospaces) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment