Skip to content

Implement TextUnmarshaler for enum type defs #947

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

Closed
philikon opened this issue Sep 16, 2019 · 1 comment
Closed

Implement TextUnmarshaler for enum type defs #947

philikon opened this issue Sep 16, 2019 · 1 comment

Comments

@philikon
Copy link

philikon commented Sep 16, 2019

Currently, the way to translate an enum value from string to the corresponding numeric value seems to be something like this:

	var enumval MyProtoEnum
	err := enumval.UnmarshalJSON([]byte(`"` + strval + `"`))

This is pretty cumbersome.

golang packages like enumer provide the ability to convert enum values from string to numeric values by implementing the standard TextUnmarshaler interface. In fact, the JSON encoder/decoder will fall back to this interface if the json.Unmarshaler interface isn't implemented.

Is there any reason not to implement this interface for proto enums? I'd be happy to provide a PR.

@dsnet
Copy link
Member

dsnet commented Sep 16, 2019

Duplicate of #866

@dsnet dsnet marked this as a duplicate of #866 Sep 16, 2019
@dsnet dsnet closed this as completed Sep 16, 2019
@golang golang locked and limited conversation to collaborators Jun 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants