[Proposal]: special case fieldmask behaviour for struct.proto types

75 views
Skip to first unread message

Johan Brandhorst

unread,
Oct 23, 2020, 6:42:38 AM10/23/20
to Protocol Buffers

Hi!

I'm one of the maintainers of the grpc-gateway, a popular third-party generator for Protobuf. As part of our runtime implementation, we have an automatic JSON-body-to-fieldmask-generator. It was written before the availability of the official Go WKT helpers for the google.protobuf.FieldMask message type, and so has a custom idea of what constitutes a valid field mask path, based on the input JSON structure. In a recent contribution, we added support for creating a field mask from the dynamic struct.proto types. For example:

Given a field named struct_field with a type google.protobuf.Struct and the incoming JSON:

{"struct_field": {"name":{"first": "bob"}, "amount": 2}}

We create the FieldMask with paths:

["struct_field.name.first", "struct_field.amount"]

This is apparently not considered a valid field mask path according to the spec in field_mask.proto.

My proposal is to extend what is considered a valid FieldMask to include this special case for the struct.proto types google.protobuf.Struct and google.protobuf.Value only.

My rationale for this is that special casing well known types is a widely practiced in the Protobuf community, and I think this field mask representation of these types will make sense to users of these types, since they're for use with fundamentally dynamic data.

For example, in JavaScript the google.protobuf.Struct type is represented by an Object, for which such a field mask would make sense. For other languages that don't have a special in-language representation for these types, field masks are generally useless already since they can't currently be used to reference anything consistently, because of the discrepancy of the implementation with other languages. We could generalise the meaning of a field mask for these types to be that which makes sense for the intent of these types.

I originally raised this idea with the Go protobuf maintainers but it was agreed that it requires a wider discussion.

Thanks for reading,

Johan Brandhorst


Josh Humphries

unread,
Oct 23, 2020, 8:35:13 AM10/23/20
to Johan Brandhorst, Protocol Buffers
+1, this feels like the only sane way to handle field masks for those two types.

I wonder if it might make sense for this special-casing to also apply to google.protobuf.Any. It is very similar to google.protobuf.Struct in its JSON form. I know the runtime and binary forms make it less practical to handle this way (since the embedded type must be known by the masker and the embedded bytes must be unmarshaled, masked, then re-marshaled). But it would be strictly more useful if it could work this way.

----
Josh Humphries
jh...@bluegosling.com


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/380bae2f-d41b-4545-a1f7-57eb89a7962fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages