Search code examples
javaprotocol-buffersgrpc-java

No instance(s) of type variable(s) exist so that String conforms to Message


I have a field called "key" of type google.protobuf.Any. I know that this is a String, so I'd like to "cast" it using the unpack() method.

However, when I write request.getKey().unpack(String.class), I get a compilation error:

Required type: Class<T>
Provided: Class<String>
reason: no instance(s) of type variable(s) exist so that String conforms to Message

I don't really understand what this really means.

This is my proto file:

message SearchCriteria{
  google.protobuf.Any key = 1;
  string storeName = 2;
}

Solution

  • You need to use some protobuf type: <T extends com.google.protobuf.Message>