Skip to content

Instantly share code, notes, and snippets.

@shairontoledo
Created October 18, 2012 16:30
Show Gist options
  • Save shairontoledo/3913014 to your computer and use it in GitHub Desktop.
Save shairontoledo/3913014 to your computer and use it in GitHub Desktop.
Scala/Play jerkson parse to model
curl -v -XPOST -H "Content-Type: text/json" http://localhost:9000/invoices -d '
{
"name": "hashcode",
"other": "here",
"person": {
"name": "maria"
},
"documents": [
{
"name": "foobar.pdf",
"size": 5555
},
{
"name": "other file.doc",
"size": 4444444
}
]
}
'
import com.codahale.jerkson.{Json => json}
case class Person(name: String)
case class Document(name: String, size: Int)
case class Invoice(
name: String,
other: Option[String],
person: Option[Person],
documents: Option[List[Document]]
)
def create = Action(parse.raw) { request =>
val bytes = new String(request.body.asBytes().get)
val invoice = json.parse[Invoice](bytes)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment