You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to the protobuf issue, int64, uint64 type is serialized into string due to a Javascript precision problem. And it seems spray cannot read the string field as Long type.
for example:
case class definition: case class Test(id: String, timestamp: Long)
protobuf IDL definition:
messageTest {
stringid=1;
int64timestamp=2;
}
the output string from protobuf json looks like:
{
"id": "xyz",
"timestamp": "1648867560"
}
When spray parse the timestamp field as Long, got the exception: "Expected Long as JsNumber, but got "1648867560" "
Suggest:
Add the String match case for LongJsonFormat:
implicitobjectLongJsonFormatextendsJsonFormat[Long] {
defwrite(x: Long) =JsNumber(x)
defread(value: JsValue) = value match {
caseJsNumber(x) if x.isValidLong => x.longValue
caseJsString(x) =>BigDecimal(x).longValue
case x => deserializationError("Expected Long as JsNumber, but got "+ x)
}
}
The text was updated successfully, but these errors were encountered:
According to the protobuf issue, int64, uint64 type is serialized into string due to a Javascript precision problem. And it seems spray cannot read the string field as Long type.
for example:
case class Test(id: String, timestamp: Long)
the output string from protobuf json looks like:
When spray parse the timestamp field as Long, got the exception: "Expected Long as JsNumber, but got "1648867560" "
Suggest:
Add the String match case for LongJsonFormat:
The text was updated successfully, but these errors were encountered: