Skip to content

Protojson handling of field masks navigating into maps #1683

Open
@patrickmeiring

Description

@patrickmeiring

https://google.aip.dev/161 proscribes 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, reviews.smith, reviews.John Smith". We use this in some places in our application.

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

  1. Rejects keys into the map that have underscores (we must camel case the keys, even though in the map we upload, the keys are in snake case). While it is expected the deserialiser converts camelCase into snake_case for ordinary keys I am surprised to see it for map keys. As a corollary, there is no way to construct a field mask that matches a map key that is not in snake_case (e.g. "MyKey").
  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 standards document for FieldMask in json proto to say 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