Skip to content

Commit

Permalink
Add test for Any containing a timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
thesamet committed Nov 23, 2023
1 parent b98221b commit 2afe38f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/test/scala/scalapb/json4s/AnyFormatSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,24 @@ class AnyFormatSpec extends AnyFlatSpec with Matchers with JavaAssertions {
ScalaJsonPrinter.toJson(input) must be(optionalAnyJson)
}

"Any" should "serialize a timestamp value" in {
val optionalAnyJson = parse("""{
"optionalAny": {
"@type": "type.googleapis.com/google.protobuf.Timestamp",
"value": "1970-01-01T00:00:00Z"
}
}""")

val input = ScalaJsonParser.fromJson[AnyContainer](optionalAnyJson)

input.getOptionalAny
.unpack[com.google.protobuf.timestamp.Timestamp] must be(
com.google.protobuf.timestamp.Timestamp()
)

ScalaJsonPrinter.toJson(input) must be(optionalAnyJson)
}

"Any" should "work when nested" in {
val nestedAny = parse("""{
| "optionalAny": {
Expand Down

0 comments on commit 2afe38f

Please sign in to comment.