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

Empty list in json string causes err in j2p #80

Open
horral opened this issue Nov 12, 2024 · 0 comments
Open

Empty list in json string causes err in j2p #80

horral opened this issue Nov 12, 2024 · 0 comments

Comments

@horral
Copy link

horral commented Nov 12, 2024

Describe the bug

When there is a value of [] in json string for a repeated field in protobuf definition, j2p will return err.

To Reproduce

func main() { content := syntax = "proto3";

package pb3;
option go_package = "pb/example";

message ExampleScalarsReq {
optional string Msg = 1;
optional double Cookie = 2;
string Path = 3;
repeated string Query = 4;
bool Header = 5;
int64 Code = 6;
}

message ExampleScalarsResp {
string Msg = 1;
optional double Cookie = 2;
int32 Status = 3;
optional bool Header = 4;
int64 Code = 5;
double Subfix = 6;
}

service TestService {
rpc ScalarsMethodTest(ExampleScalarsReq) returns (ExampleScalarsResp);
}`
opts := proto.Options{}
descriptor, err := opts.NewDesccriptorFromContent(context.Background(), "bugreport.proto", content, map[string]string{})
if err != nil {
panic(err)
}
typeDescriptor := descriptor.Methods()["ScalarsMethodTest"].Input()

input := []byte(`{"Msg": "msg", "Query": [], "Header": false, "Code": 0}`)
cv := j2p.NewBinaryConv(conv.Options{})
out, err := cv.Do(context.Background(), typeDescriptor, input)
if err != nil {
	panic(err)
}
fmt.Println(string(out))

}
`

Expected behavior

Empty list in json can be ignored or well handled when converting to protobuf.

Screenshots

image

Version:

v0.4.4

Environment:

The output of go env.

Additional context

Remove the "Query": [] or put a value in the list, then it will return without error

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

No branches or pull requests

1 participant