Add support for plumbing json_name from protoc through to proto.Properties. This will be used by the jsonpb package at a later date.
diff --git a/proto/properties.go b/proto/properties.go index d4531c0..4fe2ec2 100644 --- a/proto/properties.go +++ b/proto/properties.go
@@ -173,6 +173,7 @@ type Properties struct { Name string // name of the field, for error messages OrigName string // original name before protocol compiler (always set) + JSONName string // name to use for JSON; determined by protoc Wire string WireType int Tag int @@ -229,8 +230,9 @@ if p.Packed { s += ",packed" } - if p.OrigName != p.Name { - s += ",name=" + p.OrigName + s += ",name=" + p.OrigName + if p.JSONName != p.OrigName { + s += ",json=" + p.JSONName } if p.proto3 { s += ",proto3" @@ -310,6 +312,8 @@ p.Packed = true case strings.HasPrefix(f, "name="): p.OrigName = f[5:] + case strings.HasPrefix(f, "json="): + p.JSONName = f[5:] case strings.HasPrefix(f, "enum="): p.Enum = f[5:] case f == "proto3":
diff --git a/protoc-gen-go/generator/generator.go b/protoc-gen-go/generator/generator.go index 0f7a337..004b2d8 100644 --- a/protoc-gen-go/generator/generator.go +++ b/protoc-gen-go/generator/generator.go
@@ -1517,6 +1517,11 @@ name = name[i+1:] } } + if json := field.GetJsonName(); json != "" && json != name { + // TODO: escaping might be needed, in which case + // perhaps this should be in its own "json" tag. + name += ",json=" + json + } name = ",name=" + name if message.proto3() { // We only need the extra tag for []byte fields;