protocol-buffersgrpcproto3grpc-java

How to pass in json as payload in .proto


As per the following page I should be able to send in json payload : https://developers.google.com/protocol-buffers/docs/proto3 under 'JSON Mapping'.

I would like to send in json payload as part of the message and I have the following .proto file :

message EventsRequest{
    message RequestElement {
        struct payload = 1;
    }
    string customerId = 1;
    repeated RequestElement jsonPayload = 2;
}


message EventsResponse {
    int32 status = 1;
    string rawResponseData = 2;
    struct responseData = 3;
}

But compiling it gives me the following error :

[INFO] Compiling 1 proto file(s) to C:\workspace\...\target\generated-sources\protobuf\java
[ERROR] PROTOC FAILED: msg_service.proto:21:9: "struct" is not defined.
msg_service.proto:34:5: "struct" is not defined.

[ERROR] C:\workspace\...\src\main\proto\msg_service.proto [0:0]: msg_service.proto:21:9: "struct" is not defined.
msg_service.proto:34:5: "struct" is not defined.

I have tried 'Struct' also, but I got the same error.

Am I misunderstanding usage ? If I have to send in json payload, do I pass in as a string ?

Thanks


Solution

  • I finally ended up using String to represent json payload.