Skip to content

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

@maheshlal2910

Description

@maheshlal2910

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions