Since it is quiet trouble some in protobuf to define a flexible structure in some scenario.
for example:
message Foo {
int a = 1;
repeated int a_other = 2;
}
In fact, I don't want the service's client to pass the a
and the a_other
at the same time.
However in protobuf, we can't put these two fields in oneof
because the a_other
is a list field.
So with the above message declared, when we only pass the a_other
field, the client side cannot tell if the a
field is actually 0 or not passed by the server.
So I wonder if define a string field for Foo
like:
message Foo {
string data = 1;
}
and both the server side and the client side is agreed to treat the data
field as a JSON. So the server dumps the primitive data and the client loads it, and they live happily ever after.
But my question is, is it a common practice to do that? And what is the disadvantage of it? (this way drop the type check of course) Or is there a better way?