Allow tuple subclasses to be json serialized (#74207)
parent
dbe552b1a1
commit
b135560274
|
@ -33,7 +33,7 @@ def json_encoder_default(obj: Any) -> Any:
|
|||
|
||||
Hand other objects to the original method.
|
||||
"""
|
||||
if isinstance(obj, set):
|
||||
if isinstance(obj, (set, tuple)):
|
||||
return list(obj)
|
||||
if isinstance(obj, float):
|
||||
return float(obj)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Test Home Assistant remote methods and classes."""
|
||||
import datetime
|
||||
import json
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -87,3 +88,11 @@ def test_json_dumps_float_subclass():
|
|||
"""A float subclass."""
|
||||
|
||||
assert json_dumps({"c": FloatSubclass(1.2)}) == '{"c":1.2}'
|
||||
|
||||
|
||||
def test_json_dumps_tuple_subclass():
|
||||
"""Test the json dumps a tuple subclass."""
|
||||
|
||||
tt = time.struct_time((1999, 3, 17, 32, 44, 55, 2, 76, 0))
|
||||
|
||||
assert json_dumps(tt) == "[1999,3,17,32,44,55,2,76,0]"
|
||||
|
|
Loading…
Reference in New Issue