I defined a message which includes the 'google.protobuf.Any' type
message TestRequest {
int64 id = 1;
google.protobuf.Any items = 2;
}
and generate the related pb.gw.go file, and when to execute below auto-gen code, it failed with the error: Any JSON doesn't have '@type'
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
Curious, this definitely should be working, what does the JSON that it's trying to unmarshal look like?
The struct of TestRequest is like below one, it is auto-generated.
type TestRequest struct {
Id int64 protobuf:"varint,1,opt,name=id" json:"id,omitempty"
Items *google_protobuf1.Any protobuf:"bytes,2,opt,name=items" json:"items,omitempty"
}
What does the JSON input look like?
Pass below through request' body, @johanbrandhorst
{
"items": {
"include": [{"id": 3, "test_name": "Test_Value"}]
}
}
Yeah so you haven't specified the type URL in the JSON input. Please see documentation for the google.protobuf.Any type to see how to use it with JSON. This is not a bug.
Sorry, I didn't find any official example from documentation, could you please supply one for me to refer to? thx @johanbrandhorst
thx
Most helpful comment
https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto#L94