Skip to content

Commit

Permalink
add config to let user choose whether to render number64 type such as…
Browse files Browse the repository at this point in the history
… int64, uint64 as integers or string
  • Loading branch information
unknown committed Jan 19, 2021
1 parent b03c65e commit bd19b94
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion jsonpb/jsonpb.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ type Marshaler struct {
// Whether to render enum values as integers, as opposed to string values.
EnumsAsInts bool

// Whether to render number64 type such as int64, uint64 as integers instead of string values.
Num64AsInts bool

// Whether to render fields with zero values.
EmitDefaults bool

Expand Down Expand Up @@ -736,7 +739,7 @@ func (m *Marshaler) marshalValue(out *errWriter, prop *proto.Properties, v refle
if err != nil {
return err
}
needToQuote := string(b[0]) != `"` && (v.Kind() == reflect.Int64 || v.Kind() == reflect.Uint64)
needToQuote := string(b[0]) != `"` && ((v.Kind() == reflect.Int64 || v.Kind() == reflect.Uint64) && !m.Num64AsInts)
if needToQuote {
out.write(`"`)
}
Expand Down

0 comments on commit bd19b94

Please sign in to comment.