File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed
Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,11 @@ def object_serializer(obj):
4545
4646 :param obj: The object.
4747 """
48- return dates .format_iso_datetime (obj ) if hasattr (obj , "isoformat" ) else obj
48+ if hasattr (obj , 'isoformat' ):
49+ return dates .format_iso_datetime (obj )
50+ else :
51+ # Let the base class default method raise the TypeError
52+ return json .JSONEncoder .default (obj )
4953
5054
5155def object_deserializer (obj ):
Original file line number Diff line number Diff line change 33import json
44from datetime import date , datetime
55
6+ import pytest
67import pytz
78
89from mygeotab import serializers , dates
@@ -42,6 +43,10 @@ def test_only_date(self):
4243 data_str = json_serialize (data )
4344 assert data_str == expected_str
4445
46+ def test_unparsable_data_throws (self ):
47+ with pytest .raises (TypeError ):
48+ json_serialize ({'' })
49+
4550
4651class TestDeserialization :
4752 def test_top_level_datetime (self ):
You can’t perform that action at this time.
0 commit comments