Divergent implementations of JSON transcoding/control of default value behaviour

85 views
Skip to first unread message

Vital D'Haveloose

unread,
Aug 12, 2020, 7:12:04 AM8/12/20
to Protocol Buffers
Hello everyone,

In our setup we use Google Cloud Enpoints and the esp container in our cloud environments, but grpc-gateway for our local development. We see a difference in behaviour when transcoding protobuf to JSON, namely in how protobufs default values are transcoded. This has lead to some subtle bugs, whuch is why I am writing to you.

At the core of this issue are two different implementations of JSON transcoding:
  1. one in C++ in protobuf/src/google/protobuf/util/json_util.h with an option "always_print_primitive_fields" in the struct JsonPrintOptions
  2. another in Go in  protobuf-go/encoding/protojson/encode.go with an option "EmitUnpopulated" in the struct MarshalOptions
The esp(-v2) container uses the first one, while grpc-gateway will* use the second.

The obvious question now is: Do you plan on synchronizing both implementations, or provide extra options so they can be configured to work identically?

For extra context: I already opened an issue at the esp-v2 GitHub repo

Kind regards,
Vital D'haveloose
UZ Leuven, Belgium

(*) grpc-gateway currently uses the old 1.3.3 implementation of protobuf for Go, where the EmitUnpopulated option is called "EmitDefaults", but they are planning on upgrading.


PS: this is my first message here, if it doesn't confirm to the way things are done here please let me know. Apologies in advance :-)
Reply all
Reply to author
Forward
0 new messages