Skip to content

Instantly share code, notes, and snippets.

@lrytz
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lrytz/4fb1e66a171013f69fd8 to your computer and use it in GitHub Desktop.
Save lrytz/4fb1e66a171013f69fd8 to your computer and use it in GitHub Desktop.
scalaVersion := "2.11.2"
libraryDependencies ++= Seq("com.propensive" %% "rapture-json-jackson" % "1.0.2")
import rapture.json._
import rapture.json.jsonBackends.jackson._
case class Fruit(name: String, variants: List[String])
object Rapture extends App {
val a = json"""[
{
"name": "apple",
"variants": ["cox", "braeburn"]
},
{
"name": "orange",
"variants": ["valencia", "hamlin"]
}
]"""
println(a(1).name)
println(a(0).variants.as[List[String]] map (_.length))
val b = a.as[List[Fruit]]
println(b)
val c = Json(b.head)
assert(c == a(0))
}
@lrytz
Copy link
Author

lrytz commented Oct 17, 2014

lucmac:rapture-json-demo luc$ sbt run
[info] Loading global plugins from /Users/luc/.sbt/0.13/plugins
[info] Set current project to rapture-json-demo (in build file:/Users/luc/tmp/rapture-json-demo/)
[info] Running Rapture 
"orange"
List(3, 8)
List(Fruit(apple,List(cox, braeburn)), Fruit(orange,List(valencia, hamlin)))
[success] Total time: 1 s, completed Oct 17, 2014 4:14:41 PM

@propensive
Copy link

Use version 1.0.3 now -- I found a bug with case class extraction in 1.0.2 a couple of days ago!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment