How to send a message of type 'Any' using grpcurl?
I have this proto:
message MyRequest {
string request_id = 1;
repeated google.protobuf.Any payload = 2;
}
I am sending this request:
{
"request_id":"1",
"payload":[
{
"@type":"type.googleapis.com/com.my.type.Payload",
"id":"12345",
"message": "Hello",
}
]
}
grpcurl -plaintext -d '{"request_id": "1", "payload": [{"@type": "type.googleapis.com/com.my.type.Payload", "id": "12345", "message": "Hello"}]}' localhost:1000 com.my.service.ServiceName/Method
but I get an error: Error invoking method "com.my.service.ServiceName/Method": error getting request data: unknown message type "com.my.type.Payload"
The server is a Spring Boot project in Kotlin, so I added a bean
@Bean
fun protobufJsonFormatHttpMessageConverter(): ProtobufHttpMessageConverter? {
val typeRegistry: JsonFormat.TypeRegistry = JsonFormat.TypeRegistry.newBuilder()
.add(com.my.type.Payload.getDescriptor())
.build()
val printer = JsonFormat.printer().usingTypeRegistry(typeRegistry)
return ProtobufJsonFormatHttpMessageConverter(JsonFormat.parser(), printer)
}
But it didn't help. How to fix it?