Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add config to let user choose whether to render number64 type such as int64, uint64 as integers or string #719

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion jsonpb/jsonpb.go
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