-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
463 additions
and
20 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
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
32 changes: 32 additions & 0 deletions
32
model/src/main/scala/za/co/absa/atum/model/utils/OffsetDateTimeSerializer.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,32 @@ | ||
/* | ||
* Copyright 2021 ABSA Group Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package za.co.absa.atum.model.utils | ||
|
||
import org.json4s.JsonAST.JString | ||
import org.json4s.{CustomSerializer, JNull} | ||
|
||
import java.time.OffsetDateTime | ||
|
||
case object OffsetDateTimeSerializer extends CustomSerializer[OffsetDateTime](_ => ( | ||
{ | ||
case JString(s) => OffsetDateTime.parse(s, SerializationUtils.timestampFormat) | ||
case JNull => null | ||
}, | ||
{ | ||
case d: OffsetDateTime => JString(SerializationUtils.timestampFormat.format(d)) | ||
} | ||
)) |
61 changes: 61 additions & 0 deletions
61
model/src/main/scala/za/co/absa/atum/model/utils/SerializationUtils.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,61 @@ | ||
/* | ||
* Copyright 2021 ABSA Group Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package za.co.absa.atum.model.utils | ||
|
||
import org.json4s.jackson.Serialization | ||
import org.json4s.jackson.Serialization.{write, writePretty} | ||
import org.json4s.{Formats, NoTypeHints, ext} | ||
import za.co.absa.atum.model.dto.MeasureResultDTO.ResultValueType | ||
|
||
import java.time.format.DateTimeFormatter | ||
|
||
object SerializationUtils { | ||
|
||
implicit private val formatsJson: Formats = | ||
Serialization.formats(NoTypeHints).withBigDecimal + new ext.EnumNameSerializer(ResultValueType) + | ||
ext.UUIDSerializer + OffsetDateTimeSerializer | ||
|
||
val timestampFormat: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSX") | ||
|
||
/** | ||
* The method returns arbitrary object as a Json string. | ||
* | ||
* @return A string representing the object in Json format | ||
*/ | ||
def asJson[T <: AnyRef](obj: T): String = { | ||
write[T](obj) | ||
} | ||
|
||
/** | ||
* The method returns arbitrary object as a pretty Json string. | ||
* | ||
* @return A string representing the object in Json format | ||
*/ | ||
def asJsonPretty[T <: AnyRef](obj: T): String = { | ||
writePretty[T](obj) | ||
} | ||
|
||
/** | ||
* The method returns arbitrary object parsed from Json string. | ||
* | ||
* @return An object deserialized from the Json string | ||
*/ | ||
def fromJson[T <: AnyRef](jsonStr: String)(implicit m: Manifest[T]): T = { | ||
Serialization.read[T](jsonStr) | ||
} | ||
|
||
} |
Oops, something went wrong.