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

feat: json serialization and deserialization support stringy enums #112

Merged
merged 10 commits into from
Sep 2, 2020
Merged

feat: json serialization and deserialization support stringy enums #112

merged 10 commits into from
Sep 2, 2020

Conversation

software-dov
Copy link
Contributor

For protobuf messages that contain enum fields, it is now possible to
specify that enum variants should be serialized as names and not as integers.

E.g.

json_str = MyMessage.to_json(my_message, use_integers_for_enums=False)

Similarly, serialization from json that uses this convention is now supported.

This is useful for interoperation with other data sources that do use
strings to define enum variants in json serialization; and for
debugging, where visually inspecting data structures can be helpful,
and variant names are more informative than numerical values.

Re-addition of #107 with correct support for nested enum definitions
this time.

@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Aug 29, 2020
@codecov
Copy link

codecov bot commented Aug 29, 2020

Codecov Report

Merging #112 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #112   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           20        20           
  Lines          811       856   +45     
  Branches       136       149   +13     
=========================================
+ Hits           811       856   +45     
Impacted Files Coverage Δ
proto/_file_info.py 100.00% <100.00%> (ø)
proto/enums.py 100.00% <100.00%> (ø)
proto/fields.py 100.00% <100.00%> (ø)
proto/message.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c01800b...7929e95. Read the comment docs.

For protobuf messages that contain enum fields, it is now possible to
specify that enum variants should be serialized as names and not as integers.

E.g.

json_str = MyMessage.to_json(my_message, enum_strings=True)

Similarly, serialization from json that uses this convention is now supported.

This is useful for interoperation with other data sources that do use
strings to define enum variants in json serialization; and for
debugging, where visually inspecting data structures can be helpful,
and variant names are more informative than numerical values.

Re-addition of #107 with correct support for nested enum definitions
this time.
@software-dov software-dov merged commit 8d2e3a3 into googleapis:master Sep 2, 2020
@software-dov software-dov deleted the return-of-the-string branch September 2, 2020 23:34
busunkim96 added a commit that referenced this pull request Sep 3, 2020
software-dov pushed a commit that referenced this pull request Sep 3, 2020
@release-please release-please bot mentioned this pull request Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants