ermakov-oleg / serpyco-rs

Fast Python dataclasses serialization
MIT License
30 stars 2 forks source link

Int Enum support #59

Closed arck1 closed 1 year ago

arck1 commented 1 year ago

Now int enum in serializer.dump converted IntEnum to str value, instead of int

from dataclasses import dataclass
from enum import IntEnum

import serpyco_rs

class TestEnum(IntEnum):
    one = 1
    two = 2

@dataclass(slots=True)
class Test:
    obj_type: TestEnum

serializer = serpyco_rs.Serializer(
    Test,
    camelcase_fields=True,
    omit_none=True,
)

data = {
  'objType': 1,
}
obj = serializer.load(data)
print(obj)
// Test(obj_type=<TestEnum.one: 1>)

data = serializer.dump(Test(obj_type=TestEnum.two))
print(data)
// {'objType': '2'}
// expected {'objType': 2}

Versions: