Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.