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: Unmarshal error for Oneof field with Capital First Letter #148

Closed
awalterschulze opened this issue Mar 16, 2016 · 2 comments
Closed
Assignees

Comments

@awalterschulze
Copy link

In test_objects.proto I changed the field names to have a first letter as a capital.

message MsgWithOneof {
  oneof union {
    string Title = 1;
    int64 Salary = 2;
  }
}

This produces an error

unknown field "salary" in jsonpb.MsgWithOneof

So technically the fieldname isn't salary anymore, it is Salary, but this is what it marshals to and this is what the tags say it should be

type MsgWithOneof_Salary struct {
    Salary int64 `protobuf:"varint,2,opt,name=Salary,json=salary,oneof"`
}
@stevvooe
Copy link

We actually saw this issue, as well. It was very odd, as it only worked with the specific package from the unit tests. Once MsgWithOneof is pulled out of the package, it will not deserialize the json with a oneof field.

If more details are required, please let me know.

cc @aluzzardi

@dsymonds
Copy link
Contributor

jsonpb is specified to accept either the .proto original name, or the camelCase name. In this case, that means the acceptable set should be {Salary,salary}. It does indeed sound like a bug.

It looks like a bug specific to oneofs.

@dsymonds dsymonds self-assigned this Mar 17, 2016
@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

3 participants