Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum Strings are no longer supported #575

Closed
robin-anil opened this issue Dec 19, 2016 · 7 comments
Closed

Enum Strings are no longer supported #575

robin-anil opened this issue Dec 19, 2016 · 7 comments

Comments

@robin-anil
Copy link
Contributor

In V5 the ctor would either support string value or int value of an enum. in 6.2.1 string value is not supported when parsing from JSON. Would love to get that functionality back

message MyMessage {
 enum Type {
   CAT = 0;
   DOG = 1;
 }
 optional Type type = 1;
}
MyMessage.create({ type: 'DOG' });

does not work.

@dcodeIO
Copy link
Member

dcodeIO commented Dec 19, 2016

I see that there are valid uses for this. This would, however, affect performance in that it adds additional assertions to the constructor that are potentially (especially internally) unnecessary.

What about adding something like MyMessage.from(obj) that supports a set of options for these cases instead?

@robin-anil
Copy link
Contributor Author

MyMessage.from(obj) sound good as an interface.

However, I would like to avoid that unless the performance regresses significantly. I am looking at the large code base and any place where we will make things optional will create opportunities for error.

@dcodeIO
Copy link
Member

dcodeIO commented Dec 19, 2016

For context: This is what it currently does, which is as minimal as possible. With enums as strings, however, we'd have to check if 1. a key references a field, 2. field type is enum, 3. the value is a string and 4. whether there is a valid value for that string - 1/2 for pretty much every field, 3/4 for every enum field.

@robin-anil
Copy link
Contributor Author

robin-anil commented Dec 19, 2016

yeah bummer, MyMessage.from with options would be the way to go. I will have to train folks not to use that and use something like protoUtils.from() which keeps our code base specific options.

dcodeIO added a commit that referenced this issue Dec 22, 2016
@dcodeIO
Copy link
Member

dcodeIO commented Dec 22, 2016

Message/Type.from is now in, give it a try!

@robin-anil
Copy link
Contributor Author

Perfect! tested on an example, works great. Haven't been able to start migration due to missing protos #576

@dcodeIO
Copy link
Member

dcodeIO commented Dec 27, 2016

Closing this for now. Feel free to reopen the issue if there are any issues!

@dcodeIO dcodeIO closed this as completed Dec 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants