mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Allow tuple subclasses to be json serialized (#74207)
This commit is contained in:
parent
1555f40bad
commit
e2fe1a1c5d
@ -33,7 +33,7 @@ def json_encoder_default(obj: Any) -> Any:
|
|||||||
|
|
||||||
Hand other objects to the original method.
|
Hand other objects to the original method.
|
||||||
"""
|
"""
|
||||||
if isinstance(obj, set):
|
if isinstance(obj, (set, tuple)):
|
||||||
return list(obj)
|
return list(obj)
|
||||||
if isinstance(obj, float):
|
if isinstance(obj, float):
|
||||||
return float(obj)
|
return float(obj)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""Test Home Assistant remote methods and classes."""
|
"""Test Home Assistant remote methods and classes."""
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -87,3 +88,11 @@ def test_json_dumps_float_subclass():
|
|||||||
"""A float subclass."""
|
"""A float subclass."""
|
||||||
|
|
||||||
assert json_dumps({"c": FloatSubclass(1.2)}) == '{"c":1.2}'
|
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…
x
Reference in New Issue
Block a user