-
Notifications
You must be signed in to change notification settings - Fork 53
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
EnumSpec: Add support for MustUnmarshalText function #343
Comments
The UnmarshalText method was implemented to satisfy the I would prefer not to generate functions that panic-by-default, especially in |
That's fair. My use case is we have a datastore which stores the enums as a string representation. So we know that these strings will translate perfectly into an enum value. |
You don't necessarily have that guarantee because additions to the enum won't Suppose you add a new enum entry and deploy the change. While the deployment You always want to have a catch-all case. It can return an error upstream |
@hlin117 have you considered the case of retrieving a string from the database, with a client that was generated with an older version of the IDL and does not recognize the string? If the database stores the underlying number (perhaps alongside the string for human readers), old clients would be able to deserialize the value regardless of whether it is known to the version of the client. |
You two are right; serialization does get tricky if there are IDL inconsistencies between two instances of the service. Given these cases, I'm willing to close this issue as is. Thanks for your feedback! |
#309 implemented the
encoding.Unmarshaler
so[]byte
types can be converted into enum values. For example, this function can now be generated.It would be nice if an additional mapper,
MustUnmarshalText
, were implemented, like so:Related: #134
The text was updated successfully, but these errors were encountered: