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: add preserving_proto_field_name passthrough in MessageMeta.to_dict #211

Merged
merged 1 commit into from
Mar 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions proto/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ def from_json(cls, payload, *, ignore_unknown_fields=False) -> "Message":
Parse(payload, instance._pb, ignore_unknown_fields=ignore_unknown_fields)
return instance

def to_dict(cls, instance, *, use_integers_for_enums=True) -> "Message":
def to_dict(
cls, instance, *, use_integers_for_enums=True, preserving_proto_field_name=True
) -> "Message":
"""Given a message instance, return its representation as a python dict.

Args:
Expand All @@ -378,6 +380,9 @@ def to_dict(cls, instance, *, use_integers_for_enums=True) -> "Message":
use_integers_for_enums (Optional(bool)): An option that determines whether enum
values should be represented by strings (False) or integers (True).
Default is True.
preserving_proto_field_name (Optional(bool)): An option that
determines whether field name representations preserve
proto case (snake_case) or use lowerCamelCase. Default is True.

Returns:
dict: A representation of the protocol buffer using pythonic data structures.
Expand All @@ -387,7 +392,7 @@ def to_dict(cls, instance, *, use_integers_for_enums=True) -> "Message":
return MessageToDict(
cls.pb(instance),
including_default_value_fields=True,
preserving_proto_field_name=True,
preserving_proto_field_name=preserving_proto_field_name,
use_integers_for_enums=use_integers_for_enums,
)

Expand Down