Skip to content

Commit 80e42b8

Browse files
committed
chore: use default function instead of JSONEncoder class
1 parent 17c7bdf commit 80e42b8

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

cove_ocds/views.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,10 @@ def explore_ocds(request, pk):
317317
def ocds_show_data(json_data, ocds_show_deref_schema):
318318
new_json_data = copy.deepcopy(json_data)
319319
add_extra_fields(new_json_data, ocds_show_deref_schema)
320-
return json.dumps(new_json_data, cls=DecimalEncoder)
320+
return json.dumps(new_json_data, default=default)
321321

322322

323-
# From stackoverflow: https://stackoverflow.com/questions/1960516/python-json-serialize-a-decimal-object
324-
class DecimalEncoder(json.JSONEncoder):
325-
def default(self, o):
326-
if isinstance(o, Decimal):
327-
return float(o)
328-
return super().default(o)
323+
def default(self, obj):
324+
if isinstance(obj, Decimal):
325+
return float(obj)
326+
return json.JSONEncoder().default(obj)

0 commit comments

Comments
 (0)