-
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.
CSAS-12 move json parsers in companion-objects
- Loading branch information
Showing
9 changed files
with
106 additions
and
54 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/main/scala/com/bwsw/cloudstack/entities/common/CommonJsonFormats.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,37 @@ | ||
package com.bwsw.cloudstack.entities.common | ||
|
||
import java.time.OffsetDateTime | ||
import java.time.format.DateTimeFormatter | ||
import java.util.UUID | ||
|
||
import spray.json.{JsString, JsValue, JsonFormat, deserializationError} | ||
|
||
/** | ||
* @author Pavel Tomskikh | ||
*/ | ||
object CommonJsonFormats { | ||
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd['T'][ ]HH:mm:ss[ ]X") | ||
|
||
implicit val uuidJsonFormat: JsonFormat[UUID] = new JsonFormat[UUID] { | ||
override def read(json: JsValue): UUID = { | ||
json match { | ||
case JsString(x) => UUID.fromString(x) | ||
case x => deserializationError("Expected UUID as JsString, but got " + x) | ||
} | ||
} | ||
|
||
override def write(obj: UUID): JsValue = JsString(obj.toString) | ||
} | ||
|
||
implicit val offsetDateTimeJsonFormat: JsonFormat[OffsetDateTime] = new JsonFormat[OffsetDateTime] { | ||
override def read(json: JsValue): OffsetDateTime = { | ||
json match { | ||
case JsString(x) => OffsetDateTime.parse(x, dateTimeFormatter) | ||
case x => deserializationError("Expected OffsetDateTime as JsString, but got " + x) | ||
} | ||
} | ||
|
||
override def write(obj: OffsetDateTime): JsValue = | ||
JsString(obj.format(dateTimeFormatter)) | ||
} | ||
} |
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
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
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
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