-
Notifications
You must be signed in to change notification settings - Fork 466
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
Support Proto2 extensions in JSON coder/decoder #1002
Conversation
This is motivated purely by the existence of a new JSON conformance test. These changes are sufficient to pass that new conformance test.
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.
AnyMessageStorage
's unpackTo
has a json case, that likely should relay along the passed in ExtensionMap
when we have to decode from JSON.
I'm still filling in tests and tracking down missing bits. I'll look into Any JSON support next. |
This extends the various Any methods to accept an extensions map. So you can now unpack an Any object holding JSON that contains extensions; you "just" have to provide the appropriate extension map. Note that implicit transcoding from JSON to binary (which occurs when you ask for `.serializedData()` from an Any that was decoded from JSON without explicitly unpacking the JSON contents will always throw if the stored JSON has extensions. I experimented with several alternatives, but this seemed the best. * The Any could remember the extension map that was in effect when it was decoded, then that would be available for later transcoding. This doesn't work for binary -> JSON transcoding (because there is currently no hook that would allow the Any to capture the extensions in effect during the outer binary decode). In addition, this would add another field to Any, increasing memory requirements for a combination of features (Any + JSON + extensions) that I expect will be very rarely used (if ever). * Transcoding JSON -> Binary could silently return empty data, but I don't like silently losing data. * Transcoding JSON -> Binary could ignore extensions, but again I wasn't silently losing data, even in this obscure case.
I've filled in support and tests for Any + JSON + extensions, including figuring out a reasonable answer for implicit transcoding (TL;DR: extensions now cause JSON->binary transcoding to throw because none of the other options seemed better). I've filled in additional tests for message-valued extension fields, arrays, and a few other cases. |
… are immutable for the duration of the decode and are more heavily used in the scanner
… extensions argument be optional and default to nil
This feels like it's in pretty good shape now. Any concerns before I merge it? |
This is sufficient to pass the conformance check that was recently added, but still needs some additional testing and polish.
Addresses #993