Skip to content

Commit 1e3ed7d

Browse files
committed
adding test
1 parent 8c55211 commit 1e3ed7d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/serializers/test_union.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,3 +626,26 @@ def test_union_serializer_picks_exact_type_over_subclass_json(
626626
)
627627
assert s.to_python(input_value, mode='json') == expected_value
628628
assert s.to_json(input_value) == json.dumps(expected_value).encode()
629+
630+
631+
def test_custom_serializer() -> None:
632+
s = SchemaSerializer(
633+
core_schema.union_schema(
634+
[
635+
core_schema.dict_schema(
636+
keys_schema=core_schema.any_schema(),
637+
values_schema=core_schema.any_schema(),
638+
serialization=core_schema.plain_serializer_function_ser_schema(lambda x: x['id']),
639+
),
640+
core_schema.list_schema(
641+
items_schema=core_schema.dict_schema(
642+
keys_schema=core_schema.any_schema(),
643+
values_schema=core_schema.any_schema(),
644+
serialization=core_schema.plain_serializer_function_ser_schema(lambda x: x['id']),
645+
)
646+
),
647+
]
648+
)
649+
)
650+
assert s.to_python([{'id': 1}, {'id': 2}]) == [1, 2]
651+
assert s.to_python({'id': 1}) == 1

0 commit comments

Comments
 (0)