Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.

feat: json serialization and deserialization support stringy enums#112

Merged
software-dov merged 10 commits intogoogleapis:masterfrom
software-dov:return-of-the-string
Sep 2, 2020
Merged

feat: json serialization and deserialization support stringy enums#112
software-dov merged 10 commits intogoogleapis:masterfrom
software-dov:return-of-the-string

Conversation

@software-dov
Copy link
Copy Markdown
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
Copy Markdown

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 subscribe to this conversation on GitHub. Already have an account? Sign in.

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