lightrek
lightrek

Reputation: 981

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?

Upvotes: 1

Views: 4776

Answers (1)

J.F.
J.F.

Reputation: 15205

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) {}
}

Upvotes: 2

Related Questions