Skip to content

Commit 03f88dc

Browse files
committed
Merge pull request #158 from tamird/dont-duplicate-upstream
jsonpb: avoid duplicating upstream's struct
2 parents f5cb0d7 + b120703 commit 03f88dc

File tree

1 file changed

+2
-23
lines changed

1 file changed

+2
-23
lines changed

runtime/marshal_jsonpb.go

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,7 @@ import (
1414
// JSONPb is a Marshaler which marshals/unmarshals into/from JSON
1515
// with the "github.com/golang/protobuf/jsonpb".
1616
// It supports fully functionality of protobuf unlike JSONBuiltin.
17-
type JSONPb struct {
18-
// Whether to render enum values as integers, as opposed to string values.
19-
EnumsAsInts bool
20-
21-
// Whether to render fields with zero values.
22-
EmitDefaults bool
23-
24-
// A string to indent each level by. The presence of this field will
25-
// also cause a space to appear between the field separator and
26-
// value, and for newlines to be appear between fields and array
27-
// elements.
28-
Indent string
29-
30-
// Whether to use the original (.proto) name for fields.
31-
OrigName bool
32-
}
17+
type JSONPb jsonpb.Marshaler
3318

3419
// ContentType always returns "application/json".
3520
func (*JSONPb) ContentType() string {
@@ -61,13 +46,7 @@ func (j *JSONPb) marshalTo(w io.Writer, v interface{}) error {
6146
_, err = w.Write(buf)
6247
return err
6348
}
64-
m := &jsonpb.Marshaler{
65-
EnumsAsInts: j.EnumsAsInts,
66-
EmitDefaults: j.EmitDefaults,
67-
Indent: j.Indent,
68-
OrigName: j.OrigName,
69-
}
70-
return m.Marshal(w, p)
49+
return (*jsonpb.Marshaler)(j).Marshal(w, p)
7150
}
7251

7352
// marshalNonProto marshals a non-message field of a protobuf message.

0 commit comments

Comments
 (0)