1 /*
2  * sys-emu - A system emulator for tutorials
3  * Copyright (C) 2018 - 2019 osdevelopment-info
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17  */
18 package info.osdevelopment.sysemu.model
19 
20 import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
21 import spray.json.{DefaultJsonProtocol, JsNumber, JsObject, JsString, JsValue, RootJsonFormat, _}
22 
23 trait SysEmuJsonProtocol extends SprayJsonSupport with DefaultJsonProtocol {
24 
25   implicit object SystemJsonFormat extends RootJsonFormat[SystemModel] {
26 
27     override def read(json: JsValue): SystemModel = {
28       deserializationError("Deserialization is not supported for Systems")
29       /*json.asJsObject.getFields("uuid") match {
30         case Seq(JsString(uuid)) =>
31           new System(Some(UUID.fromString(uuid)))
32       }*/
33     }
34 
35     override def write(obj: SystemModel): JsValue = {
36       JsObject(("uuid", JsString(obj.uuid.toString)))
37     }
38 
39   }
40 
41   implicit object ProcessorJsonFormat extends RootJsonFormat[ProcessorModel] {
42 
43     override def read(json: JsValue): ProcessorModel = {
44       deserializationError("Deserialization is not supported for Processors")
45     }
46 
47     override def write(obj: ProcessorModel): JsValue = {
48       JsObject(
49         ("name", JsString(obj.name)),
50         ("maxMemory", JsNumber(obj.maxMemory))
51       )
52     }
53 
54   }
55 
56   implicit object MessageJsonFormat extends RootJsonFormat[MessageModel] {
57 
58     override def read(json: JsValue): MessageModel = {
59       deserializationError("Deserialization is not supported for Message")
60     }
61 
62     override def write(obj: MessageModel): JsValue = {
63       JsObject(
64         ("message", JsString(obj.message))
65       )
66     }
67 
68   }
69 
70 }
Line Stmt Id Pos Tree Symbol Code
28 254 1209 - 1255 Literal <nosymbol> "Deserialization is not supported for Systems"
28 256 1188 - 1188 Select spray.json.deserializationError$default$3 spray.json.`package`.deserializationError$default$3
28 255 1188 - 1188 Select spray.json.deserializationError$default$2 spray.json.`package`.deserializationError$default$2
28 257 1188 - 1256 Apply spray.json.deserializationError spray.json.`package`.deserializationError("Deserialization is not supported for Systems", spray.json.`package`.deserializationError$default$2, spray.json.`package`.deserializationError$default$3)
36 262 1470 - 1517 Apply spray.json.JsObject.apply spray.json.JsObject.apply(scala.Tuple2.apply[String, spray.json.JsString]("uuid", spray.json.JsString.apply(obj.uuid.toString())))
36 259 1497 - 1514 Apply java.util.UUID.toString obj.uuid.toString()
36 258 1480 - 1486 Literal <nosymbol> "uuid"
36 261 1479 - 1516 Apply scala.Tuple2.apply scala.Tuple2.apply[String, spray.json.JsString]("uuid", spray.json.JsString.apply(obj.uuid.toString()))
36 260 1488 - 1515 Apply spray.json.JsString.apply spray.json.JsString.apply(obj.uuid.toString())
44 265 1673 - 1673 Select spray.json.deserializationError$default$3 spray.json.`package`.deserializationError$default$3
44 264 1673 - 1673 Select spray.json.deserializationError$default$2 spray.json.`package`.deserializationError$default$2
44 263 1694 - 1743 Literal <nosymbol> "Deserialization is not supported for Processors"
44 266 1673 - 1744 Apply spray.json.deserializationError spray.json.`package`.deserializationError("Deserialization is not supported for Processors", spray.json.`package`.deserializationError$default$2, spray.json.`package`.deserializationError$default$3)
48 275 1815 - 1917 Apply spray.json.JsObject.apply spray.json.JsObject.apply(scala.Tuple2.apply[String, spray.json.JsString]("name", spray.json.JsString.apply(obj.name)), scala.Tuple2.apply[String, spray.json.JsNumber]("maxMemory", spray.json.JsNumber.apply(obj.maxMemory)))
49 268 1851 - 1859 Select info.osdevelopment.sysemu.model.ProcessorModel.name obj.name
49 267 1834 - 1840 Literal <nosymbol> "name"
49 270 1833 - 1861 Apply scala.Tuple2.apply scala.Tuple2.apply[String, spray.json.JsString]("name", spray.json.JsString.apply(obj.name))
49 269 1842 - 1860 Apply spray.json.JsString.apply spray.json.JsString.apply(obj.name)
50 271 1872 - 1883 Literal <nosymbol> "maxMemory"
50 274 1871 - 1909 Apply scala.Tuple2.apply scala.Tuple2.apply[String, spray.json.JsNumber]("maxMemory", spray.json.JsNumber.apply(obj.maxMemory))
50 273 1885 - 1908 Apply spray.json.JsNumber.apply spray.json.JsNumber.apply(obj.maxMemory)
50 272 1894 - 1907 Select info.osdevelopment.sysemu.model.ProcessorModel.maxMemory obj.maxMemory
59 277 2067 - 2067 Select spray.json.deserializationError$default$2 spray.json.`package`.deserializationError$default$2
59 276 2088 - 2134 Literal <nosymbol> "Deserialization is not supported for Message"
59 279 2067 - 2135 Apply spray.json.deserializationError spray.json.`package`.deserializationError("Deserialization is not supported for Message", spray.json.`package`.deserializationError$default$2, spray.json.`package`.deserializationError$default$3)
59 278 2067 - 2067 Select spray.json.deserializationError$default$3 spray.json.`package`.deserializationError$default$3
63 284 2204 - 2264 Apply spray.json.JsObject.apply spray.json.JsObject.apply(scala.Tuple2.apply[String, spray.json.JsString]("message", spray.json.JsString.apply(obj.message)))
64 280 2223 - 2232 Literal <nosymbol> "message"
64 283 2222 - 2256 Apply scala.Tuple2.apply scala.Tuple2.apply[String, spray.json.JsString]("message", spray.json.JsString.apply(obj.message))
64 282 2234 - 2255 Apply spray.json.JsString.apply spray.json.JsString.apply(obj.message)
64 281 2243 - 2254 Select info.osdevelopment.sysemu.model.MessageModel.message obj.message