ddibiase
ddibiase

Reputation: 1502

Passing object as array in body in proto3

I'm wondering how I can pass an array as the body of the message without having to specify a key. I can easily do:

message TypeResponse {
  message Type {
    string ID = 1;
    string Name = 2;
    string Description = 3;
    string IsMobile = 4;
    string IsTablet = 5;
    string IsDesktop = 6;
  }
  repeated Type types = 1;
}

That would response with:

{
  "types": [
    {
      "ID": 1
      ...
    }
  ]
}

I'd like to structure my response as the following to match my REST API:

[
    {
      "ID": 1
      ...
    },
    {
      "ID": 2
      ...
    }
]

Upvotes: 3

Views: 2952

Answers (1)

Carl Mastrangelo
Carl Mastrangelo

Reputation: 6628

Proto requires that the top level concept is a message, which spills into the JSON mapping.

Something you could do is just skip the first characters until you reach a [ character, and then drop the very last character which will be a ]. The output format for JSON is specified by the Proto3 spec, so you can reasonably depend on the format.

Upvotes: 1

Related Questions