Created
September 9, 2011 10:54
-
-
Save fwielstra/1205941 to your computer and use it in GitHub Desktop.
Parsing a nested JSON object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"trip": { | |
"deviceId":"822083cb7c63dfe0694b9795399f594897bf7015c734d644b317b327426921d0", | |
"plannedDeparture":"2011-09-30T13:46:00+0200", | |
"fromStation":"ut", | |
"plannedDepartureFirstStation":"2011-09-30T13:46:00+0200", | |
"viaStation":"zwd", | |
"toStation":"hvsp", | |
"plannedArrivalLastStation":"2011-09-30T15:04:00+0200" | |
}, | |
"notifications":{ | |
"minutesBeforeDeparture":10, | |
"guard":true, | |
"minutesBeforeArrival":5, | |
"checkoutWarning":true, | |
"repeatOnDays":[true, false, true, false, true, false, true] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Trip( | |
deviceId:String, | |
plannedDeparture: DateTime, | |
fromStation: String, | |
plannedDepartureFirstStation:DateTime, | |
viaStation: Option[String], | |
toStation: String, | |
plannedArrivalLastStation: DateTime) { | |
} | |
object TripJsonProtocol extends DefaultJsonProtocol with DateTimeFormats { | |
implicit val recordFormat = jsonFormat(Trip, | |
"deviceId", | |
"plannedDeparture", | |
"fromStation", | |
"plannedDepartureFirstStation", | |
"viaStation", | |
"toStation", | |
"plannedArrivalLastStation") | |
} | |
case class Notification( | |
minutesBeforeDeparture: Option[Int], | |
guard: Option[Boolean], | |
minutesBeforeArrival: Option[Int], | |
checkoutWarning: Option[Boolean], | |
repeatOnDays: Option[List[Boolean]]) { | |
} | |
object NotificationJsonProtocol extends DefaultJsonProtocol { | |
implicit val recordFormat = jsonFormat(Notification, | |
"minutesBeforeDeparture", | |
"guard", | |
"minutesBeforeArrival", | |
"checkoutWarning", | |
"repeatOnDays") | |
} | |
case class NotificationPlan(trip: Trip, notification: Notification) { | |
} | |
object NotificationPlanJsonProtocol extends DefaultJsonProtocol { | |
// ???? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment