protoreflect
protoreflect copied to clipboard
an int64 value in pb is changed to string when use PbToJson Message.MarshalJSONPB
This is expected because the range of a 64-bit integer is not necessarily representable by JSON numbers (which are typically interpreted as 64-bit floats, so they cannot accurately represent all integers greater than 2^53).
See the docs on the JSON format for protocol buffers here, which specifies that 64-bit integers be marshaled as strings.
This seems like a far issue. https://github.com/protocolbuffers/protobuf/issues/5015#issuecomment-411847550. Regard less of your reason, if i don't use the json output for a javascript interpreter , instead I only use it for show. i would perfer a numerical value. There are a lot of people strongly requesting this feature. One issue closed, another opened.
change int64 to int32 instead, or use json.Marshal instead of jsonpb.Marshal.
I don't see a compelling reason why this dynamic message package should provide different/more JSON marshaling capabilities than the main protobuf runtime. Sorry.
change int64 to int32 instead, or use json.Marshal instead of jsonpb.Marshal.
Some people are using C++ rather than golang.
I don't see a compelling reason why this dynamic message package should provide different/more JSON marshaling capabilities than the main protobuf runtime. Sorry.
I am using C++ in the client. The communication data with the server is JSON. The server-side developer don't want to use protobuffer. But I need a structure definition in the client. So I write proto and generate structure then serialize the structure as string. The server-side cannot parse string to int64. So I need to make some change.
In a word, I use protobuffer as a structure-to-json tool. I don't need ask other people follow the "int64 serialize as string" rule.