Comments (15)
Verified, v1.20.0 still reports missing "value" field
as does the current v1.34.1.
from protobuf.
#759 (comment)
Found this issue, says it was fixed, but the same behaviour reproduces on google.golang.org/[email protected]
from protobuf.
I filed protocolbuffers/protobuf#17099 as a first step to get clarity on this. I'm not even sure if we can change the Go behavior if we wanted to because it would be a backwards incompatible change. However, accepting this might be better than the incosistency with C++ and Java and the inability to parse their output.
from protobuf.
I only tested it with C++, but C++ doesn't accept:
{"@type":"type.googleapis.com/google.protobuf.Empty","value":{}}
It fails with
invalid JSON in google.protobuf.Any @ <any>: message google.protobuf.Empty, near 1:62 (offset 61): no such field: 'value'
from protobuf.
Ah, thanks for looking into that.
Given the amount of inconsistency in the ecosytem, I suspect every implementation will need to accept both the case where it is preset with {}
and also missing. That said, I think it's up to the protobuf team to declare which form is "more correct" and we should probably output that.
from protobuf.
This is the same as #759. Someone responded with protocolbuffers/protobuf#5390 (comment). I'm uncertain if that is affirmative as there has been no further action/decision and the issue was simply closed as inactive. May want to reopen that issue.
from protobuf.
I think this is the other side of #759: I don't know if we should marshal an Empty with a value of {} or no value, but we definitely should parse what other languages are producing.
from protobuf.
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.
That said, the protobuf ecosystem is full of inconsistencies where the implementations do not follow what is documented. Thus, I agree with what @neild says. Pragmatically we should just do whatever the other languages do.
from protobuf.
I’m on the same page as dsnet. Technically, we’re following the spec as written… but that doesn’t much matter if other implementations are accepting this and we’re not.
from protobuf.
Changing behaviour of golang protojson.Unmarshal
can be a viable compromise, otherwise compatibility would break.
from protobuf.
I don't see an urgent reason to change Marshal's behavior. However, Unmarshal must be able to parse the output of other languages, even if that output is technically wrong. (I have no opinion on whether it is technically wrong or not.)
from protobuf.
I definitely wasn’t advocating for changing the marshalling output. Only for accepting.
from protobuf.
We still end up with the problem that the output generated by Go cannot be parsed by the other languages. But I agree that extending the unmarshalling makes it more permissive and thus might not be fine (unless someone depends on an error being reported).
from protobuf.
output generated by Go cannot be parsed by the other languages
Perhaps I missed it, but the original post only mentioned protojson.Unmarshal
. Is there a report of whats generated by protojson.Marshal
not being accepted in another language implementation?
from protobuf.
#759 is the report for V1's marshaling issue. With the response in protocolbuffers/protobuf#5390 (comment), I think we decided to keep the behavior for V2.
I was mistaken in my comment above that this is similar to that marshaling issue. I don't mind having the unmarshaling logic accept what the other languages output.
from protobuf.
Related Issues (20)
- Editions language feature: (pb.go).struct_tag HOT 11
- Make M option overwrite `option go_package` in the `.proto` file (as opposed to return an error) HOT 5
- related to #1054 and similar "plugin output is unparseable" errors HOT 4
- Random 0xfeff / ZERO WIDTH NO-BREAK SPACE being added to returned string values HOT 3
- custom options doesn't seem to work for protobuf map fields HOT 2
- Can protobuf provide tags for customized message generated fields? HOT 2
- encoding/protojson: unmarshalBytes assumes no padding if byte string length is not divisible by 4 HOT 27
- Service crash caused by encoding HOT 3
- structpb.Struct.MarshalJSON is not consistent HOT 4
- --gofast_out option in protoc discards inline comments from .proto files HOT 1
- How to redefine the json tag? HOT 2
- proto.Equal does not check for nested invalidity HOT 5
- A terrible work-around: HOT 2
- protoreflect x dynamicpb interaction: should descriptors match names or be pointer-identical?
- add proto.IsWellFormed helper function to validate that a message value is well-formed HOT 1
- google.protobuf.Empty as response serializes to not empty response depending on request headers HOT 2
- protocmp: Panic on embed message field comparison HOT 7
- Panic when use enum.String() before main() HOT 2
- Proposal: remove presumably unused purego support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protobuf.