Skip to content
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

Merged
merged 18 commits into from
Jun 4, 2020

Conversation

tbkka
Copy link
Collaborator

@tbkka tbkka commented May 14, 2020

This is sufficient to pass the conformance check that was recently added, but still needs some additional testing and polish.

Addresses #993

This is motivated purely by the existence of a new JSON conformance
test.  These changes are sufficient to pass that new conformance
test.
Copy link
Collaborator

@thomasvl thomasvl left a 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.

@tbkka
Copy link
Collaborator Author

tbkka commented May 16, 2020

I'm still filling in tests and tracking down missing bits. I'll look into Any JSON support next.

tbkka added 4 commits May 26, 2020 16:56
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.
@tbkka
Copy link
Collaborator Author

tbkka commented Jun 3, 2020

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.

@tbkka tbkka marked this pull request as ready for review June 3, 2020 21:58
@tbkka
Copy link
Collaborator Author

tbkka commented Jun 3, 2020

This feels like it's in pretty good shape now. Any concerns before I merge it?

@tbkka tbkka merged commit 57420fb into apple:master Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants