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

Can you differentiate between an empty map vs field not provided? #552

Closed
Ianwww opened this issue Feb 21, 2018 · 4 comments
Closed

Can you differentiate between an empty map vs field not provided? #552

Ianwww opened this issue Feb 21, 2018 · 4 comments

Comments

@Ianwww
Copy link

Ianwww commented Feb 21, 2018

With this proto definition

 message UpdateMessage {
    string id = 1;
    map[string]string my_map = 2;
 }

 service YourService {
  rpc Echo(UpdateMessage) returns (StringMessage) {
    option (google.api.http) = {
      patch: "/update"
      body: "*"
    };
  }
 }

I'd like to send a request like
{"id":"myid","my_map":{}}
and set MyMap to an empty map.

Is this possible? Currently, when this field is provided, my service thinks this field is unset(MyMap==Nil). I'm working in golang.

@achew22
Copy link
Collaborator

achew22 commented Feb 23, 2018

I, unfortunately, am not as expert with protos as I probably should be, but I don't believe there is a easy way to do that that doesn't involve fieldmasks which we don't currently support. That said there is some interest in implementing that in the gateway. Would you be interested in taking that sort of project on?

@Ianwww
Copy link
Author

Ianwww commented Mar 8, 2018

thanks for the response. I had to move forward and use a wrapper around a map to handle this. I'm not going to be able to work on this with my present workload.

@johanbrandhorst
Copy link
Collaborator

You have to use field masks. This will be automatically supported with #671.

@mayank-dixit
Copy link

mayank-dixit commented Nov 14, 2018

With this proto definition

 message UpdateMessage {
    string id = 1;
    map[string]string my_map = 2;
 }

 service YourService {
  rpc Echo(UpdateMessage) returns (StringMessage) {
    option (google.api.http) = {
      patch: "/update"
      body: "*"
    };
  }
 }

I'd like to send a request like
{"id":"myid","my_map":{}}
and set MyMap to an empty map.

Is this possible? Currently, when this field is provided, my service thinks this field is unset(MyMap==Nil). I'm working in golang.

@ Ianwww @achew22 Use this maybe: https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/StringValue

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

4 participants