Empty list in json string causes err in j2p
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
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
Hi, @horral . Thank you for pointing out the issue. This problem has been fixed in latest dynamicgo version. PR: https://github.com/cloudwego/dynamicgo/pull/99