Sunday, 18 August 2013

converting multiple json objects into scala objects

converting multiple json objects into scala objects

How do I read multiple json objects from a request and convert them into
my own custom object. For example, lets say we are retrieving a list of
users with the following json:
{
"users":[
{
"name": "Bob",
"age": 31.0,
"email": "bob@gmail.com"
},
{
"name": "Kiki",
"age": 25.0,
"email": null
}
]
}
and my case class looks like the following
case class User(firstName: String, age: Double, email: String)
In this case the firstName value is differnt from the "name" json value.
How do I get a Seq[User] from the given json file with the different
names. I can't find any examples where someone is reading from a json file
with multiple objects.
Thanks in advance.

No comments:

Post a Comment