Skip to content

Commit

Permalink
cmd/protoc-gen-go: remove json struct tags from unexported fields
Browse files Browse the repository at this point in the history
This commit does not change behavior because the encoding/json
package ignores unexported fields. To encode a Protobuf message
into JSON, users should reach for protobuf/encoding/protojson.

With this change, the generated code (.pb.go files) passes go vet.
I also made the integration test run go vet so that we do not regress.

For golang/protobuf#1657

Fixes golang/protobuf#1658

Change-Id: I0a677d09e4517b2649bfcfe76a49194c7ccbb823
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/641036
Reviewed-by: Damien Neil <[email protected]>
Reviewed-by: Chressie Himpel <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
stapelberg committed Jan 8, 2025
1 parent 84f7738 commit fe8430d
Show file tree
Hide file tree
Showing 23 changed files with 1,086 additions and 1,073 deletions.
4 changes: 3 additions & 1 deletion cmd/protoc-gen-go/internal_gengo/opaque.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ func opaqueGenMessageField(g *protogen.GeneratedFile, f *fileInfo, message *mess
}
tags := structTags{
{"protobuf", protobufTagValue},
{"json", jsonTagValue},
}
if !message.isOpaque() {
tags = append(tags, structTags{{"json", jsonTagValue}}...)
}
if field.Desc.IsMap() {
keyTagValue := fieldProtobufTagValue(field.Message.Fields[0])
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fe8430d

Please sign in to comment.