This repository has been archived by the owner on Dec 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iss #8: json full view logic, some common serializers
- Loading branch information
Showing
6 changed files
with
161 additions
and
30 deletions.
There are no files selected for viewing
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
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
14 changes: 14 additions & 0 deletions
14
server/src/main/scala/ru/maizy/cheesecake/server/jsonapi/JsonApiMarshallers.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ru.maizy.cheesecake.server.jsonapi | ||
|
||
/** | ||
* Copyright (c) Nikita Kovaliov, maizy.ru, 2016 | ||
* See LICENSE.txt for details. | ||
*/ | ||
|
||
import ru.maizy.cheesecake.server.jsonapi.models.{ AppConfigs, FullView } | ||
import ru.maizy.cheesecake.server.marshalers.CommonJsonMarshallers | ||
|
||
trait JsonApiMarshallers extends CommonJsonMarshallers { | ||
implicit val configFormat = jsonFormat1(AppConfigs) | ||
implicit val fullViewFormat = jsonFormat2(FullView) | ||
} |
14 changes: 0 additions & 14 deletions
14
server/src/main/scala/ru/maizy/cheesecake/server/jsonapi/JsonMarshalers.scala
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
server/src/main/scala/ru/maizy/cheesecake/server/jsonapi/models/FullView.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package ru.maizy.cheesecake.server.jsonapi.models | ||
|
||
import ru.maizy.cheesecake.server.service.EndpointFQN | ||
|
||
/** | ||
* Copyright (c) Nikita Kovaliov, maizy.ru, 2016 | ||
* See LICENSE.txt for details. | ||
*/ | ||
|
||
// FIXME: tmp format | ||
case class FullView(endpoints: Seq[EndpointFQN], tmpToStringRes: String = "world") |
69 changes: 69 additions & 0 deletions
69
server/src/main/scala/ru/maizy/cheesecake/server/marshalers/CommonJsonMarshallers.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package ru.maizy.cheesecake.server.marshalers | ||
|
||
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport | ||
import spray.json.{ DefaultJsonProtocol, JsObject, JsString, JsValue, RootJsonFormat } | ||
import spray.json.{ JsNumber, pimpAny } | ||
import ru.maizy.cheesecake.server.service.{ Endpoint, EndpointFQN, HttpAddress, HttpEndpoint, IpAddress, Service} | ||
import ru.maizy.cheesecake.server.service.SymbolicAddress | ||
|
||
/** | ||
* Copyright (c) Nikita Kovaliov, maizy.ru, 2016 | ||
* See LICENSE.txt for details. | ||
*/ | ||
|
||
// TODO: how to use only writer for case classes | ||
trait CommonJsonMarshallers extends SprayJsonSupport with DefaultJsonProtocol { | ||
implicit val serviceFormat = jsonFormat1(Service) | ||
|
||
implicit object IpAddressFormat extends RootJsonFormat[IpAddress] { | ||
def write(ip: IpAddress): JsValue = JsObject( | ||
"type" -> JsString("ip"), | ||
"ip" -> JsString(ip.hostName), | ||
"hostname" -> JsString(ip.hostName) | ||
) | ||
override def read(json: JsValue): IpAddress = ??? | ||
} | ||
|
||
implicit object SymbolicAddressFormat extends RootJsonFormat[SymbolicAddress] { | ||
def write(ip: SymbolicAddress): JsValue = JsObject( | ||
"type" -> JsString("symbolic"), | ||
"hostname" -> JsString(ip.hostName) | ||
) | ||
override def read(json: JsValue): SymbolicAddress = ??? | ||
} | ||
|
||
implicit object HttpAddressFormat extends RootJsonFormat[HttpAddress] { | ||
def write(address: HttpAddress): JsValue = address match { | ||
case ip: IpAddress => ip.toJson | ||
case symb: SymbolicAddress => symb.toJson | ||
case _ => JsObject("hostname" -> JsString(address.hostName)) | ||
} | ||
override def read(json: JsValue): HttpAddress = ??? | ||
} | ||
|
||
implicit object HttpEndpointFormat extends RootJsonFormat[HttpEndpoint] { | ||
def write(endpoint: HttpEndpoint): JsValue = JsObject( | ||
"type" -> JsString("http"), | ||
"address" -> endpoint.address.toJson, | ||
"port" -> JsNumber(endpoint.port), | ||
"path" -> JsString(endpoint.path), | ||
"headers" -> endpoint.headers.toJson | ||
) | ||
override def read(json: JsValue): HttpEndpoint = ??? | ||
} | ||
|
||
implicit object EndpointFormat extends RootJsonFormat[Endpoint] { | ||
def write(address: Endpoint): JsValue = address match { | ||
case ep: HttpEndpoint => ep.toJson | ||
case _ => JsObject( | ||
"type" -> JsString("unknown") | ||
) | ||
} | ||
|
||
override def read(json: JsValue): Endpoint = ??? | ||
} | ||
|
||
implicit val httpEndpointFormat = jsonFormat4(HttpEndpoint) | ||
|
||
implicit val endpointFQN = jsonFormat2(EndpointFQN) | ||
} |