grpc-dotnet icon indicating copy to clipboard operation
grpc-dotnet copied to clipboard

Support application/grpc+json

Open JamesNK opened this issue 6 years ago • 4 comments

Today we support application/grpc+proto and application/grpc (which infers proto).

Post V1, support JSON. Consider supporting custom message formats, e.g. application/grpc+ini

JamesNK avatar Feb 23 '19 22:02 JamesNK

What is application/grpc+json? I read this https://grpc.io/blog/grpc-with-json but I don't understand the point of this thing. What does it mean for the codegen? What parts of the stack stay the same and what part ends up being different?

davidfowl avatar Feb 24 '19 00:02 davidfowl

At a low level really the only difference is the marshallers. They hang off Method<,>, and I believe there is a 1 to 1 relationship between them.

Either we would extend Method<,> to support different marshallers depending on the message type, method.GetRequestMarshaller("proto").Deserializer, or we'd have different Method<,> instances for different message types.

Tooling is the difficult side. Grpc.Tools doesn't support JSON, but people could create types with their own binder methods that have method instances that supported JSON. With JSON code gen isn't as important because serialization is a lot more forgiving. The marshaller for JSON could be (message) => Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message))

JamesNK avatar Feb 24 '19 01:02 JamesNK

Tooling may not be a difficulty. Protobufs have a defined JSON mapping (spec) and the official c# protobuf library includes support for JSON marshalling using the above specification (docs). A single grpc-dotnet server should be able to serve both JSON and protobufs using the same Grpc.Tools codegen'd classes. I implemented protobufs or JSON support over HTTP (using aspcore) a while back and the protobuf tooling worked great for it.

plaisted avatar Feb 26 '19 02:02 plaisted

will this enable using json with grpc and getting rid of the highly problematic protobufs? (i.e. bad nullability support)

JohnGalt1717 avatar Aug 16 '22 16:08 JohnGalt1717