raccoon
raccoon copied to clipboard
Inconsistent JSON <> Protobuf API standard
Bug
- json message isn't serialised with correct Protobuf based JSON encoding standard.
- Resulting in failure when sending JSON requests from valid protobuf encoded json string.
Context:
- Protobuf style guide states that JSON keys should be in camelCase, and protobuf keys/field names should be in snake_case.
- The standard for encoding Timestamp is to convert it into a string of RFC 3339.
- Thus, when a Request Payload is serialised. It uses CamelCase and also converts the timestamp/sent_time into a string.
- However, since raccoon uses standard encoding/json package to deserialise, it does not correctly deserialise camelCase keys of Json.
- It also fails to deserialise the date string.
Fix
- Start using protobuf's official encoding/protojson package for deserialisation.
- It adhere's to the style guide of protobuf, which supports deserialisation of both snake_case and camelCase keys in JSON.
- However, existing JSON contract will break since new json contract will expect sent_time to be of type string instead of an object
{seconds: number, nanos: number}
. This could be fixed by updating existing clients to use protobuf's json encoders instead of language's default json encoders.