Re: [protobuf] How to workaround enum sibling issue in Java

2018-07-22 Thread 'Jian Dai' via Protocol Buffers
Thanks a lot for the nice help. It works. 

Jian

> On Jul 21, 2018, at 8:39 AM, Feng Xiao  wrote:
> 
> 
> 
> On Fri, Jul 20, 2018 at 10:22 PM jiandai via Protocol Buffers 
> mailto:protobuf@googlegroups.com>> wrote:
> Hi there, 
> 
> I am creating a protobuf message to match with a JSON data in legacy 
> application. The problem is that legacy JSON has mulitple enum data, and some 
> of them have the same enum name, like "NONE". 
> 
> I know protobuf requires enum name uniqueness on the scope of package and 
> protobuf convert to JSON based on enum name. I was wondering, in my case 
> here, is there any way that I can, 
> 
> 1. workaround protobuf enum sibling constriction and build the enums with the 
> same name in a same package? Or, 
> 2. request protobuf converter to convert enum into different name, and vice 
> versa?
> You can put enums with the same name in the same package but they have to be 
> contained in separate message types. I.e.:
> 
> message Foo {
>   enum MyEnum {
> NONE = 0;
>   }
> }
> 
> message Bar {
>   enum MyEnum {
> NONE = 0;
>   }
> }
> 
> Because we only use the short name in JSON, the above 2 enums will end up 
> with the same JSON value "NONE".
>  
> 
> Many thanks in advance for the nice help. 
> 
> Jian
> 
> -- 
> 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 protobuf+unsubscr...@googlegroups.com 
> .
> To post to this group, send email to protobuf@googlegroups.com 
> .
> 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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


Re: [protobuf] How to workaround enum sibling issue in Java

2018-07-21 Thread 'Feng Xiao' via Protocol Buffers
On Fri, Jul 20, 2018 at 10:22 PM jiandai via Protocol Buffers <
protobuf@googlegroups.com> wrote:

> Hi there,
>
> I am creating a protobuf message to match with a JSON data in legacy
> application. The problem is that legacy JSON has mulitple enum data, and
> some of them have the same enum name, like "NONE".
>
> I know protobuf requires enum name uniqueness on the scope of package and
> protobuf convert to JSON based on enum name. I was wondering, in my case
> here, is there any way that I can,
>
> 1. workaround protobuf enum sibling constriction and build the enums with
> the same name in a same package? Or,
> 2. request protobuf converter to convert enum into different name, and
> vice versa?
>
You can put enums with the same name in the same package but they have to
be contained in separate message types. I.e.:

message Foo {
  enum MyEnum {
NONE = 0;
  }
}

message Bar {
  enum MyEnum {
NONE = 0;
  }
}

Because we only use the short name in JSON, the above 2 enums will end up
with the same JSON value "NONE".


>
> Many thanks in advance for the nice help.
>
> Jian
>
> --
> 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 protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> 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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


[protobuf] How to workaround enum sibling issue in Java

2018-07-20 Thread jiandai via Protocol Buffers
Hi there, 

I am creating a protobuf message to match with a JSON data in legacy 
application. The problem is that legacy JSON has mulitple enum data, and 
some of them have the same enum name, like "NONE". 

I know protobuf requires enum name uniqueness on the scope of package and 
protobuf convert to JSON based on enum name. I was wondering, in my case 
here, is there any way that I can, 

1. workaround protobuf enum sibling constriction and build the enums with 
the same name in a same package? Or, 
2. request protobuf converter to convert enum into different name, and vice 
versa?

Many thanks in advance for the nice help. 

Jian

-- 
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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.