That does work, but it seems like it creates a lot of unnecessary work if
there are many fields.
Is there a better way to handle a schema more like this?
{ type: "error", message: "wrong"} or { type:"ok", a: 1, b:2, c:3, d:4,
... }.
On Monday, May 9, 2016 at 3:12:19 PM UTC-4, Feng Xiao wrote:
>
>
>
> On Fri, May 6, 2016 at 8:18 PM, Marco <[email protected] <javascript:>>
> wrote:
>
>> I'm looking to generate de/serialization for json tagged union messages
>> from an external rest api, eg.
>> { type: "error", message: "wrong"} or { type:"ok", response: { a: 1, b:
>> 2}}.
>>
>> Reading the docs it seems like an any valued field the type field
>> modified json_name would work similarly, although this isn't supported.
>>
>> Is there an existing .proto message that would map to those messages?
>> Perhaps
>> with some annotation to this more obvious schema, or being able to specify
>> a custom tag to determine which case of a oneof is in use (instead of the
>> default enum value)?
>>
> How about something like:
>
> message Response {
> string type = 1;
> message Content {
> int32 a = 1;
> int32 b = 2;
> }
> oneof OneofResponse {
> string message = 2;
> Content response = 3;
> }
> }
>
> ?
>
>
>> message Error {
>> string message = 1;
>> }
>>
>> message Second {
>> int64 response = 1;
>> }
>>
>> message MyUnion {
>> oneof Either {
>> Error err = 1;
>> Ok ok = 2;
>> }
>> }
>>
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Protocol Buffers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/protobuf.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.