Skip to content

Instantly share code, notes, and snippets.

@lrytz
Last active Aug 29, 2015
Embed
What would you like to do?
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

Loading

@propensive
Copy link

propensive commented Oct 19, 2014

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

Loading

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