Skip to content

Commit

Permalink
cleanup RecordMetadata.formatRecordMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
t3hnar committed Nov 4, 2023
1 parent b7ce030 commit 0d14df7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,14 @@ object RecordMetadata {

val empty: RecordMetadata = RecordMetadata()


implicit val formatRecordMetadata: OFormat[RecordMetadata] = {

val format = Json.format[RecordMetadata]

// TODO expiry: temporary, remove after 01-02-2020
val writes = new OWrites[RecordMetadata] {
def writes(a: RecordMetadata) = {
Json.toJsObject(a.header) ++ format.writes(a)
}
}

val reads = format.orElse((json: JsValue) => {
val reads = format.orElse { json: JsValue =>
json
.validate[HeaderMetadata]
.map { a => RecordMetadata(a, PayloadMetadata.empty) }
})

OFormat(reads, writes)
}
OFormat(reads, format)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class RecordMetadataTest extends AnyFunSuite with Matchers {
("data", Json.obj(("key0", "value0"))))),
("payload", Json.obj(
("expireAfter", "1 day"),
("data", Json.obj(("key1", "value1"))))),
("data", Json.obj(("key0", "value0"))))),
("data", Json.obj(("key1", "value1"))))))),
(
RecordMetadata(
HeaderMetadata(Json.obj(("key0", "value0")).some),
Expand All @@ -37,8 +36,7 @@ class RecordMetadataTest extends AnyFunSuite with Matchers {
("header", Json.obj(
("data", Json.obj(("key0", "value0"))))),
("payload", Json.obj(
("data", Json.obj(("key1", "value1"))))),
("data", Json.obj(("key0", "value0"))))),
("data", Json.obj(("key1", "value1"))))))),
(
RecordMetadata(
HeaderMetadata.empty,
Expand All @@ -55,8 +53,7 @@ class RecordMetadataTest extends AnyFunSuite with Matchers {
Json.obj(
("header", Json.obj(
("data", Json.obj(("key0", "value0"))))),
("payload", Json.obj()),
("data", Json.obj(("key0", "value0"))))))
("payload", Json.obj()))))
} {
test(s"formatRecordMetadata reads & writes $json") {
Json.toJson(metadata) shouldEqual json
Expand Down

0 comments on commit 0d14df7

Please sign in to comment.