We're using proto3 and trying to write a proto message to generate a golang structure which can be marshaled as a JSON output with a particular structure.
The data needs to have nested arrays of mixed types (specifically, the vCard format as specified here)
The problem we're running into is generating an array with mixed types. For example, just "vcardArray:["vcard",100] that is, an array with a string and an int32
If we use Oneof
as so:
message Vcard {
oneof vcard {
string name = 1;
int32 value = 2;
}
}
We can generate something like:
[
{"name":"vcard"},
{"int":100}
]
If we use Any as so:
message VcardArray {
repeated google.protobuf.Any vcard = 1;
}
We can generate:
[
{
type: "type.googleapis.com/google.protobuf.StringValue",
value: "vcard"
},
{
type: "type.googleapis.com/google.protobuf.Int32Value",
value: 100
},
]
We expect the next JSON:
"vcardArray": [
"vcard",
[
[ "version", {},"text","4.0"],
[ "tel", {
"pref":"1",
"type":[
"work",
"voice"
]
}
],
[...],
[...]
]
]
The central question, is it possible to generate arrays of of mixed elements such as ["vcard",[...]] and if so, how can it be done?