REGnosys / rosetta-code-generators

Write code generators for any language, based on the rosetta DSL
Apache License 2.0
17 stars 33 forks source link

Python - serialisation of Enum classes #233

Closed vjuge closed 1 year ago

vjuge commented 1 year ago

this is a duplication of https://github.com/finos/common-domain-model/issues/2233, feel free to delete it

Please introduce slight modification in python distribution, in order to allow json dumps serialization of classes derived from Enum.

for instance, an enum which contains only strings (the same approach is applicable for enum made of int, etc)

from enum import Enum

class PartyIdentifierTypeEnum(Enum): 

python 3.11+ would require

from enum import StrEnum

class PartyIdentifierTypeEnum(StrEnum): 

while python 3.9+ would require

from enum import Enum

class PartyIdentifierTypeEnum(str, Enum): 

the later is a preferred solution imo, since it would be compatible with more configurations. (what's the required python version for using cdm, if any ?)