-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Feature - Allow serialize Enum object #2457
base: develop
Are you sure you want to change the base?
Conversation
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.
Note for reviewer
if len(val) == 1 and list(val.keys())[0] in cls._registered_types.keys(): | ||
return cls._registered_types[list(val.keys())[0]]._pythonify(list(val.values())[0]) |
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.
This if
command handles the case where a dataclass instance is serialized into a dictionary.
For example, UserAttribute("email", "credential_mail", default="[email protected]") will be serialized to
{ "USER_ATTRIBUTE": {"name": "email", "credentials_name": "credentials_mail", "default": "[email protected]"}
The key is used to identify the type of the serialized object.
LGTM 😃 |
elif dynamic_type == "enum": | ||
return _TemplateHandler._to_enum(actual_val) |
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.
Just to be sure I understand: This case does not cover internal enums (SCOPE and FREQUENCY), as they are caught up by:
if dynamic_type in cls._registered_types.keys():
return cls._registered_types[dynamic_type]._pythonify(actual_val)
which transforms the string SCENARIO:SCOPE
into a Scope instance with the SCENARIO value.
Your case transforms the string Gender.male:enum
into the Gender enum with the male value.
Am I correct?
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.
yes, all registered types are handled first, then the enum
What type of PR is this? (check all applicable)
Description
This PR allows the _BaseSerializer to serialize and deserialize an Enum object.