string interpreted as StringValue
eum2o opened this issue · comments
Tested with v1.8.7:
Apparently grpcurl auto-boxes string
into a google.protobuf.StringValues
.
Example
Take this protobuf:
syntax = "proto3";
import "google/protobuf/wrappers.proto";
message Foobar {
string s1 = 1;
google.protobuf.StringValue s2 = 2;
}
I can successfully use grpcurl by calling something like
grpcurl -d '{"s1": "val1", "s2": "val2"}' ...
which is weird because I'd expect the JSON to look as follows:
grpcurl -d '{"s1": "val1", "s2": { "value" : "val2" }}' ...
But I'f use the latter, I get the error
Error invoking method "<foobar>": error getting request data: json: cannot unmarshal object into Go value of type string
@eum2o, this is expected behavior. grpcurl
uses the canonical JSON format for protobuf: https://protobuf.dev/programming-guides/proto3/#json
In that table, you'll see a row for "Wrapper types", one of which is google.protobuf.StringValue
. You'll see in that table that all of the wrapper types are encoded in JSON as just the value they wrap -- not as a JSON object.