-
Notifications
You must be signed in to change notification settings - Fork 108
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
JSON unmarshaling by default errors on unknown field inputs. #477
Comments
This is pretty reasonable - we ought to make this sort of customization more straightforward. We're definitely not going to make discarding unknown fields the default behavior. It doesn't seem clearly better than the current behavior, it's a significant change post-1.0, and it doesn't match the default for Tentatively, I think it's best not to special-case this one toggle. If we're going to do anything, I'd prefer |
After thinking about this a bit more, I'd prefer to leave this configurability to third-party packages. From the discussion on #500:
In short, use |
I'm hopeful that this gets incorporated at least into and official buf package in the future. thanks. |
I think it would be good to configure connect-go so that servers reject unknown JSON fields by default, however clients should ignore unknown fields. That allows a server to implement a new API or add new fields over time without having every client update to the latest version immediately (creating a tight coupling between the two). |
@pkwarren that's a great point. Technically the protobuf spec allows fields to be added and removed as you update your implementation. The current implementaiton for JSON doesn't follow that phlosophy, but rather pedantically requires you to have all clients match your current server implementation. |
@koblas, the protobuf language guide says that a "Proto3 JSON parser should reject unknown fields by default", so it is not perfectly straight-forward to find the least surprising behavior. That said, @pkwarren's suggestion seems practical. connectrpc/connect-es#613 is a case where a user was surprised by the same default behavior in connect-es clients. |
Y'all have convinced me - I hadn't considered how tightly the current behavior couples servers and clients. We should definitely make clients discard unknown fields. Once we've done that, it seems pretty reasonable to have servers do the same - they already do so for binary inputs, and it seems reasonable to accommodate clients sending old fields that are now deleted (and reserved). |
The current JSON unmarshaling logic tightly couples clients and servers: clients can't unmarshal messages containing new fields, and servers can't unmarshal messages containing ancient fields that have since been deleted. This is counter to the typical protobuf forward- and backward-compatibility story, and is far more restrictive than the binary codec. This PR loosens the default behavior to discard unknown fields. Fixes #477.
The current JSON unmarshaling logic tightly couples clients and servers: clients can't unmarshal messages containing new fields, and servers can't unmarshal messages containing ancient fields that have since been deleted. This is counter to the typical protobuf forward- and backward-compatibility story, and is far more restrictive than the binary codec. This PR loosens the default behavior to discard unknown fields. Fixes #477.
The current JSON unmarshaling logic tightly couples clients and servers: clients can't unmarshal messages containing new fields, and servers can't unmarshal messages containing ancient fields that have since been deleted. This is counter to the typical protobuf forward- and backward-compatibility story, and is far more restrictive than the binary codec. This PR loosens the default behavior to discard unknown fields. Fixes #477.
Is your feature request related to a problem? Please describe.
I'm porting a bunch of infrastructure from twirp to connect and one of the things I just got caught by was the JSON Codec for Service Unmarshaling by default signals an error for fields present in JSON not present in the protobuf description.
Describe the solution you'd like
Either:
options := protojson.UnmarshalOptions{DiscardUnknown: true}
) by default.connect.WithJsonDiscardUnknown()
.Describe alternatives you've considered
My current solution was to cut-n-paste out the JSON codec and provide it back in as an option to my service handler.
Additional context
Nope.
The text was updated successfully, but these errors were encountered: