-
Notifications
You must be signed in to change notification settings - Fork 1.4k
google.protobuf.Timestamp deserialization incompatible with canonical JSON representation #893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
For reference: https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto protobuf.js uses so called wrappers to provide additional functionality on top of the raw data types (seconds, nanos). There's one for any, but none for timestamp yet. |
Hello and thanks so much for such a quick reply! Could you please expand a bit on the topic of wrappers (or, alternatively, point me to a comment / document) ? Am I correct in thinking, that if there was a wrapper for 'google.protobuf.Timestamp', it would've been used instead of default "fromObject" functionality, whenever Now that I think of it, may it be that I am doing something completely wrong? At the moment I am receiving JSON representations of protobuf messages from a HTTP API and I am using |
Running into this now, was there any resolution? |
I think we need to revive this PR #929 (and the implementation present in the fork: https://github.com/zia-ai/protobuf.js/tree/feature/struct) |
protobuf3 writes Timestamp as a plain string in the RFC 3339 format (2018-06-19T18:27:29.350Z). wrappers.js
converter.js genValuePartial_fromObject
Update: I'm seeing the wrapper getting called from the unit test, but when I compile a .proto file into javascript, the wrapper is not called. Not sure what I'm doing wrong there, but the only way I can get it to "work" is to include the wrapper code in the genValuePartial_fromObject and genValuePartial_toObject:
edit: nanos factor is 1000000, not 1000 (if anyone wants to use the above) |
+1 |
1 similar comment
+1 |
#1258 addresses this |
Any news on this? I am seeing something similar on C#. When trying to use the Jsonparser I get the following exception using it like Google.Protobuf.InvalidProtocolBufferException: Expected string value for Timestamp |
Ref: protobufjs/protobuf.js#893 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ### Summary by CodeRabbit --- - Bug Fix: Improved error handling in `ApertureClient` class to ensure better logging and request acceptance when the Aperture server is unavailable. - Refactor: Enhanced readability of the `ShouldRun()` method in `flow.ts`. - Style: Reformatted the `DisableFailOpen()` method for better code clarity. - Bug Fix: Adjusted the `Decision()` method to correctly handle timestamp issues in the `checkResponse` object, ensuring accurate flow decisions. - New Feature: Added immutability to the `FlowDecision` object using `Object.freeze()`, enhancing data security and integrity. --- <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024, issue still persists |
I am consuming a HTTP API, that is generated by grpc-gateway.
In protobuf3 docs (https://developers.google.com/protocol-buffers/docs/proto3#json) it says, that timestamps are encoded as RFC 3339 strings.
So, any Timestamp fields end up as strings when encoded to JSON.
However, generated xxx.fromObject methods expect Timestamp fields to be objects with
seconds
andnanos
fields, so messages, that contain non-null Timestamp fields are never deserialized.I am using generated static-code.
Is there any additional info, that I could provide? Maybe I am just misunderstanding something?
The text was updated successfully, but these errors were encountered: