Skip to content

Instantly share code, notes, and snippets.

@fwielstra
Created September 9, 2011 10:54
Show Gist options
  • Save fwielstra/1205941 to your computer and use it in GitHub Desktop.
Save fwielstra/1205941 to your computer and use it in GitHub Desktop.
Parsing a nested JSON object
{
"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]
}
}
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