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

Fields are nil in resultant map when default valus are set in proto #36

Open
maheshlal2910 opened this issue Aug 9, 2018 · 0 comments

Comments

@maheshlal2910
Copy link

maheshlal2910 commented Aug 9, 2018

We noticed funny behaviour when trying to deserialize a byte array that was generated from a proto. I understand that default values don't get serialized, and hence deserializing them is not possible. However, I believe that setting up a default value when converting a bytearray to a map would be immensely helpful, instead of having no keys at all and that resulting in a nil.

Let me illustrate this with an example: Assuming you have a Person proto. Considering we are using proto3, I will not be using required and optional.

package your.namespace.person;

option java_outer_classname = "Example";

message Person {
  int32  id    = 1;
  string name  = 2;
  string email = 3;
  repeated string likes = 4;
}

Now given I have populated a protobuf map of type Person using
{ :id 123 :name "test subject"}

and serialized it to bytes; Once I try to deserialize it, I get a hashmap of
{:id 123 :name "test subject"}

I would instead expect default values to be populated on the resultant map. So; on deserializing, I would expect
{ :id = 123; :name = "test subject" :email = <empty string> :likes = <empty list> }

Is there something I am missing or is this desired behaviour? If it is something that is by design, would you be happy to accept a patch that allows us to populate default values for the fields not sent on the wire?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant