-
Notifications
You must be signed in to change notification settings - Fork 41
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
Enum deserialization doesn't work with non-simple enum values #585
Comments
@morrison12 currently non-primitive enum value is not supported. def enum(self, arg: DeField[Any]) -> str:
return f"{typename(arg.type)}({self.primitive(arg)})" https://github.com/yukinarit/pyserde/blob/main/serde/de.py#L936-L937 I will take a look if I can easily support non-primitive enum value |
hmm currently pyserde relies on enum constructor for deserialization, but to support non-primitive enum value such as tuple requires to generate (de)serialize functions for enum. It is a quite bit of work.. |
The one thought I had was to establish the convention (for |
The workaround isn't too horrible, something like: class A(Enum):
...
@serde
@dataclass
class B:
....
foo: A = serde_field(serializer=lambda x:x.name, deserializer=lambda x:A[x]) |
Enum
s with "complex" values, for example atuple
, can't be deserialized as shown from the example below.In the example below, it appears it is because the values are deserialized as a
list
but only atuple
is permitted !?!If the name and not the value(s) were serialized for
Enum
s this could be avoided but would break the cases where the value is desired. Perhaps serialize the name for all butIntEnum
andStrEnum
?Example
Output
Environment Details
The text was updated successfully, but these errors were encountered: