Skip to content

Commit 31f9780

Browse files
committed
fix: use custom serializers for custom data classes values
1 parent ead7183 commit 31f9780

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

aws_lambda_powertools/event_handler/openapi/encoders.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def jsonable_encoder( # noqa: PLR0911
9595
exclude_unset=exclude_unset,
9696
exclude_defaults=exclude_defaults,
9797
exclude_none=exclude_none,
98+
custom_serializer=custom_serializer,
9899
)
99100

100101
# Enums

tests/functional/event_handler/_pydantic/test_openapi_encoders.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,25 @@ def serializer(value):
253253

254254
# THEN we should get the custom serializer output
255255
assert result == {"kind": "serialized"}
256+
257+
258+
def test_openapi_encode_custom_serializer_dataclasses():
259+
# GIVEN a sequence with a custom class
260+
class CustomClass:
261+
__slots__ = []
262+
263+
@dataclass
264+
class Order:
265+
kind: CustomClass
266+
267+
order = Order(kind=CustomClass())
268+
269+
# AND a custom serializer
270+
def serializer(value):
271+
return "serialized"
272+
273+
# WHEN we call jsonable_encoder with the nested dictionary and unserializable value
274+
result = jsonable_encoder(order, custom_serializer=serializer)
275+
276+
# THEN we should get the custom serializer output
277+
assert result == {"kind": "serialized"}

0 commit comments

Comments
 (0)