Skip to content

Protojson handling of field masks navigating into maps #1683

@patrickmeiring

Description

@patrickmeiring

https://google.aip.dev/161 says that for a field of type map (e.g. map<string, string>), we may allow field masks in requests that traverse into the map, e.g.

  // Reviews for the back cover. The key is the author of the review,
  // and the value is the text of the review.
  //
  // Valid field masks: reviews, reviews.smith, reviews.`John Smith`
  map<string, string> reviews = 2;

We use this in some places in our application.

However, I find that the FieldMask protojson implementation in go:

  1. Rejects keys that have underscores (we must camel case the keys as if they are proto fields). This causes identification issues for a map with e.g. both the keys john_smith or JohnSmith as the only protojson field mask that will pass validation is reviews.johnSmith which deserialises to reviews.john_smith.
  2. The backtick notation (`) described in that API under "Map fields" does not work.

It seems the relevant code is here:
golang/protobuf/v2/encoding/protojson/well_known_types.go

I haven't been able to find a specification for FieldMask in protojson that says authoritatively what it should/should not accept. Can you clarify? Are the AIPs recommending things the proto spec can't support? Is there a problem with the go protojson implementation?

Using google.golang.org/protobuf v1.36.5

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