Advertisement
Guest User

Untitled

a guest
May 9th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.93 KB | None | 0 0
  1. package com.nubeiot.dsl
  2.  
  3. import spray.json.{DefaultJsonProtocol, JsValue}
  4.  
  5. object JsonStuff {
  6.  
  7.   case class Response(items: Seq[Thing])
  8.  
  9.   case class Thing(thingId: String, features: Features)
  10.  
  11.   case class Features(histories: Histories)
  12.  
  13.   case class Histories(properties: Map[String, History])
  14.  
  15.   case class History(data: Seq[Value])
  16.  
  17.   case class Row(thingId: String, point: String, time: Long, value: Double)
  18.  
  19.   case class Value(ts: Long, `val`: JsValue) {
  20.     def value = `val`.toString.filterNot(c => c == '"' || c == '\\').toDouble
  21.   }
  22.  
  23.   object MyJsonProtocol extends DefaultJsonProtocol {
  24.     implicit val valueFormat = jsonFormat2(Value)
  25.     implicit val historyFormat = jsonFormat1(History)
  26.     implicit val historiesFormat = jsonFormat1(Histories)
  27.     implicit val featuresFormat = jsonFormat1(Features)
  28.     implicit val thingFormat = jsonFormat2(Thing)
  29.     implicit val responseFormat = jsonFormat1(Response)
  30.   }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement