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

Proto type int64 get the error format in http swagger post body #91

Closed
zengzhengrong opened this issue Jun 16, 2020 · 3 comments
Closed

Comments

@zengzhengrong
Copy link

proto file

message Userprofile{
  int64 user_id = 1;
  ...
 }

pb.go

type Userprofile struct {
	UserId int64 `protobuf:"varint,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
  ....
}

{8CE3E2BC-BF98-4D2F-BC36-BFE9087C216E}_20200616155100
It’s very strange ~, but I try to use int32 , it's work fine

@utrack
Copy link
Owner

utrack commented Jun 16, 2020

Hi, it is not an error and in fact a Protobuf JSON mapping spec: https://developers.google.com/protocol-buffers/docs/proto3#json_mapping

It is done like that because JS integers are precise up to 2^52 instead of int64's 2^63: grpc-ecosystem/grpc-gateway#219 (comment)

So if you were sending JSON of {"foo":(number bigger than 2^52)} many JSON parsers won't parse that number.

@bullgare
Copy link
Contributor

Yes, we've run into this limitation a couple of years ago also.

@zengzhengrong
Copy link
Author

Thank ~! Got it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants