protobuf
protobuf copied to clipboard
Java/C++/Python implementation inconsistent with proto json spec when marshaling empty proto in any proto
See https://github.com/golang/protobuf/issues/1620 for full context.
The protobuf Go implementation gerates a different output and expects a different input when converting a google.protobuf.Empty proto nested in and google.protobuf.Any proto to and from JSON compared to C++, Java and Python.
According to the discussion on the issue, the Go protobuf implementation seems to be consistent with the spec but inconsistent with other languages.
Copying the relevant parts from the other issue:
(not using quotes here to keep the original formatting): start quote from dsnet:
The documentation for google.protobuf.Any.value
says:
[The
value
field] must be a valid serialized protocol buffer of the above specified type.
Elsewhere, the documentation for google.protobuf.Any
says:
If the embedded message type is well-known and has a custom JSON representation, that representation will be embedded adding a field
value
which holds the custom JSON in addition to the@type
field.
Then, the documentation for google.protobuf.Empty
says:
The JSON representation for
Empty
is empty JSON object{}
.
Thus, it seems that the current behavior is correct.
end quote
Is our interpretation/understanding of the documentation incorrect? Would it be reasonable to adjust the documentation to reflect the behavior of the C++/Java/Python? Alternatively, could the behavior of C++/Java be adjusted to align with the documentation? I assume this is cost prohibitive and even aligning the Go implementation with C++ and Java might not be easy.