Skip to content
New issue

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

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

Already on GitHub? # to your account

int64 AND uint64 become string using jsonpb marshal #718

Open
anotherGoogleFan opened this issue Jan 16, 2021 · 0 comments · May be fixed by #719
Open

int64 AND uint64 become string using jsonpb marshal #718

anotherGoogleFan opened this issue Jan 16, 2021 · 0 comments · May be fixed by #719

Comments

@anotherGoogleFan
Copy link

anotherGoogleFan commented Jan 16, 2021

The code is so simple:

package main

import (
	"os"

	"github.com/gogo/protobuf/jsonpb"
	"github.com/gogo/protobuf/proto"
)

func main() {
	marshaller := jsonpb.Marshaler{
		EnumsAsInts:  true,
		EmitDefaults: false,
		OrigName:     true,
	}

	marshaller.Marshal(os.Stdout, &TestInt{
		Ori: 16,
	})
}

type TestInt struct {
	Ori uint64 `protobuf:"varint,1,opt,name=ori,proto3" json:"ori,omitempty"`
}

func (m *TestInt) Reset()         { *m = TestInt{} }
func (m *TestInt) String() string { return proto.CompactTextString(m) }
func (*TestInt) ProtoMessage()    {}

I got {"ori":"16"}.
But what I want is {"ori":16}.

I tried many times and found that if ori defined as uint8 int8 uint int uint32 int32 I can get {"ori":16}.
But if it is int64 uint64 it becomes {"ori":"16"}.

@anotherGoogleFan anotherGoogleFan changed the title EnumsAsInts does not work in jsonpb config int64 AND uint64 become string using jsonpb marshal Jan 18, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
1 participant