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 JSON tags are considered a deprecated feature of protobuf generation, as one should be using the protojson package, instead of the standard library’s encoding/json which has several caveats to its usage that mean that the official proto3 JSON mapping could not be implemented properly with it.
The JSON tags are considered a deprecated feature of protobuf generation, as one should be using the protojson package, instead of the standard library’s encoding/json which has several caveats to its usage that mean that the official proto3 JSON mapping could not be implemented properly with it.
What caveats is there? protojson has a lot unexpected behaviour i prefer avoid using it replacing with JSONBuiltin. The only trouble i faced - hardcoded omitempty by the compiler.
Problem
When I generate
.pb.go
files usingprotoc
, its generating structs with json tags where there areomitempty
option in each of the fields:Proto3:
Generated go struct:
Solutions
Option to tell protoc compiler to not generate structs with
omitempty
json tags (For example some arg likeprotoc --json-emitall
)Protobuf to support json-tag related options:
For example, on the top of the .proto file:
Or, support for some per message option like:
Desired Result
So that I can get:
The text was updated successfully, but these errors were encountered: