Skip to content

Commit 2afe38f

Browse files
committed
Add test for Any containing a timestamp
For scalapb/ScalaPB#1612
1 parent b98221b commit 2afe38f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/test/scala/scalapb/json4s/AnyFormatSpec.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,24 @@ class AnyFormatSpec extends AnyFlatSpec with Matchers with JavaAssertions {
120120
ScalaJsonPrinter.toJson(input) must be(optionalAnyJson)
121121
}
122122

123+
"Any" should "serialize a timestamp value" in {
124+
val optionalAnyJson = parse("""{
125+
"optionalAny": {
126+
"@type": "type.googleapis.com/google.protobuf.Timestamp",
127+
"value": "1970-01-01T00:00:00Z"
128+
}
129+
}""")
130+
131+
val input = ScalaJsonParser.fromJson[AnyContainer](optionalAnyJson)
132+
133+
input.getOptionalAny
134+
.unpack[com.google.protobuf.timestamp.Timestamp] must be(
135+
com.google.protobuf.timestamp.Timestamp()
136+
)
137+
138+
ScalaJsonPrinter.toJson(input) must be(optionalAnyJson)
139+
}
140+
123141
"Any" should "work when nested" in {
124142
val nestedAny = parse("""{
125143
| "optionalAny": {

0 commit comments

Comments
 (0)