Search code examples
javanullprotocol-buffersgrpcgrpc-java

Can gPRC (protobuf) return a null message?


Our client side calls a gRPC server, which ideally should return a MyMessage response object.

But can this MyMessage object be null? or gRPC cannot return null object because if it is null, grpc will throw exception?


Solution

  • Answering your question, check these Google docs where says:

    Note that no Java protocol buffer methods accept or return nulls unless otherwise specified.

    So it seems gRPC can't return null. By the way you can take a look to to google.protobuf.empty and reference for Java

    You can define your proto like:

    import "google/protobuf/empty.proto";
    
    service SomeService {
        rpc SomeOperation (google.protobuf.Empty) returns (google.protobuf.Empty) {}
    }