raccoon icon indicating copy to clipboard operation
raccoon copied to clipboard

Inconsistent JSON <> Protobuf API standard

Open punit-kulal opened this issue 1 year ago • 0 comments

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:

  1. Protobuf style guide states that JSON keys should be in camelCase, and protobuf keys/field names should be in snake_case.
  2. The standard for encoding Timestamp is to convert it into a string of RFC 3339.
  3. Thus, when a Request Payload is serialised. It uses CamelCase and also converts the timestamp/sent_time into a string.
  4. However, since raccoon uses standard encoding/json package to deserialise, it does not correctly deserialise camelCase keys of Json.
  5. It also fails to deserialise the date string.

Fix

  1. Start using protobuf's official encoding/protojson package for deserialisation.
  2. It adhere's to the style guide of protobuf, which supports deserialisation of both snake_case and camelCase keys in JSON.
  3. 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.

punit-kulal avatar Aug 22 '23 04:08 punit-kulal