-
Notifications
You must be signed in to change notification settings - Fork 73
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
Ignore unknown JSON fields by default #642
Conversation
const o = options ?? {}; | ||
o.ignoreUnknownFields ??= true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the change. The rest is tests.
Nice. A few small questions:
Also, we need to update the docs here: https://github.com/bufbuild/protobuf-es/blob/main/docs/runtime_api.md#json |
Yes, a breaking change. Only if you rely on clients and server to reject new fields. But still a breaking change.
Yes, I think this docs page fits best. |
Just ran into this in production, easy to work around but just wanted to chime in that this seems like a more sensible and expected default. |
Agree that this should definitely be the default. One of the biggest reasons for us to use protobufs was to have backwards compatibility, and we just discovered (the hard way) that our production deployment was not backwards-compatible because of using the default options here... Would be great to see this PR being merged! |
…-json-fields-by-default
@russellhaering, @arvid220u, thanks for the feedback. This is going out with the next release. |
When changing a schema, servers are usually updated first. With the default behavior of the JSON format to reject unknown fields, this causes an issue with in simple cases such as adding a field to a response message. #613 is a good example.
This PR changes the default behavior of both clients and servers to ignore unknown fields. It is equivalent to the following option (for a Transport, or for the ConnectRouter):
After this PR is merged, clients or servers can opt in to reject unknown fields by providing
jsonOptions: { ignoreUnknownFields: false }
.