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

jsonpb: fix Unmarshal when single enum value is provided for a repeated enum field #209

Closed
wants to merge 1 commit into from

Conversation

maditya
Copy link

@maditya maditya commented Aug 2, 2016

…d enum field

@maditya
Copy link
Author

maditya commented Oct 6, 2016

ping @bcmills

@@ -634,6 +634,9 @@ func (u *Unmarshaler) unmarshalValue(target reflect.Value, inputValue json.RawMe
target.Set(reflect.New(targetType.Elem()))
target = target.Elem()
}
if target.Kind() != reflect.Int32 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead this, in line 624, you can check whether the target can be an enum type.

maybeEnum := target.Kind() == reflect.Int32 ||
target.Kind() == reflect.Ptr && targetType.Elem().Kind() == reflect.Int32 // proto2
if maybeEnum && inputValue[0] == '"' && prop != nil && prop.Enum != "" {
...
}

The advantage is the case this change addresses will be handled by the json unmarshal code so the error message will be a bit clearer.

"json: cannot unmarshal string into Go value of type []json.RawMessage"
vs.
"mismatched type, want int32, got slice"

@dsnet dsnet added the jsonpb label May 19, 2017
@cybrcodr
Copy link
Contributor

I'd like to follow up on this PR. It would be nice to have this merged in if you can follow through the review comment. Thanks.

@dsnet dsnet changed the title fix jsonpb unmarshal when single enum value is provided for a repeate… jsonpb: fix Unmarshal when single enum value is provided for a repeated enum field Mar 9, 2018
@dsnet
Copy link
Member

dsnet commented Jun 6, 2018

Apparently this is a duplicate of #627, which was recently merged.

@dsnet dsnet closed this Jun 6, 2018
@maditya maditya deleted the enum-fix branch January 17, 2019 06:15
@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

Successfully merging this pull request may close these issues.

4 participants