Skip to content

Instantly share code, notes, and snippets.

@propensive
Created January 17, 2015 01:21
Show Gist options
  • Save propensive/abf6eaef3fc071a5c7a2 to your computer and use it in GitHub Desktop.
Save propensive/abf6eaef3fc071a5c7a2 to your computer and use it in GitHub Desktop.
Welcome to Scala version 2.10.4 (OpenJDK 64-Bit Server VM, Java 1.6.0_27).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import rapture.json._; import jsonBackends.scalaJson._
import rapture.json._
import jsonBackends.scalaJson._
scala> class SpecialInt(val i: Int) extends AnyVal
defined class SpecialInt
scala> val myJson = json"""{ "value": 42 }"""
myJson: rapture.json.Json = {"value":42}
scala> myJson.value.as[SpecialInt]
res0: SpecialInt = SpecialInt@2a
scala> val newJson = json"""{ "output": $res0 }"""
newJson: rapture.json.Json = {"output":42}
scala> case class Foo(first: Int, second: SpecialInt)
defined class Foo
scala> json"""{ "first": 1, "second": 2 }""".as[Foo]
res2: Foo = Foo(1,SpecialInt@2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment