You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The situation is unfortunate and can't be changed without breaking existing code. The generation of the json tag pre-dated the formalization of the JSON<->PB specification. In it's current state, using encoding/json does not produce JSON that conforms to any particular pre-defined schema.
The jsonpb package exists to implement the aforementioned JSON specification since it is not possible to do so using the json tags alone. Rather than fixing the json tag, it should probably be removed entirely and have #256 addressed instead.
dsnet
changed the title
JSON Struct Tags are generated with the wrong naming convention
protoc-gen-go: JSON struct tags are generated with the wrong naming convention
Sep 11, 2018
What version of protobuf and what language are you using?
% go version
go version go1.11 darwin/amd64
What did you do?
Observed that generated code looked funny:
What did you expect to see?
I expected the
json=
output in theprotobuf:
tag to match thejson:
tag field name.What did you see instead?
JSON tag field naming that doesn't match JSON field norms.
The problem is that g.goTag uses
GetJsonName
but the actual JSON tag generation uses*field.Name
.Reccomendation:
Switch https://github.com/golang/protobuf/blob/master/protoc-gen-go/generator/generator.go#L2488 to use
GetJsonName
just like https://github.com/golang/protobuf/blob/master/protoc-gen-go/generator/generator.go#L1548The text was updated successfully, but these errors were encountered: