File tree 2 files changed +14
-5
lines changed
aws_lambda_powertools/utilities/idempotency/serialization
2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -12,11 +12,11 @@ class BaseIdempotencySerializer(ABC):
12
12
13
13
@abstractmethod
14
14
def to_dict (self , data : Any ) -> Dict :
15
- pass
15
+ raise NotImplementedError ( "Implementation of to_dict is required" )
16
16
17
17
@abstractmethod
18
18
def from_dict (self , data : Dict ) -> Any :
19
- pass
19
+ raise NotImplementedError ( "Implementation of from_dict is required" )
20
20
21
21
22
22
class BaseIdempotencyModelSerializer (BaseIdempotencySerializer ):
Original file line number Diff line number Diff line change 1
- from dataclasses import dataclass
1
+ from dataclasses import asdict , dataclass
2
+ from typing import Any , Dict
2
3
3
4
from aws_lambda_powertools .utilities .idempotency import (
4
5
DynamoDBPersistenceLayer ,
@@ -29,9 +30,17 @@ class OrderOutput:
29
30
order_id : int
30
31
31
32
33
+ def custom_to_dict (x : Any ) -> Dict :
34
+ return asdict (x )
35
+
36
+
37
+ def custom_from_dict (x : Dict ) -> Any :
38
+ return OrderOutput (** x )
39
+
40
+
32
41
order_output_serializer : CustomDictSerializer = CustomDictSerializer (
33
- to_dict = lambda x : x . asdict () ,
34
- from_dict = lambda x : OrderOutput ( ** x ) ,
42
+ to_dict = custom_to_dict ,
43
+ from_dict = custom_from_dict ,
35
44
)
36
45
37
46
You can’t perform that action at this time.
0 commit comments