diff options
| author | Vik Fearing | 2022-05-16 12:41:00 +0000 |
|---|---|---|
| committer | Magnus Hagander | 2022-05-16 12:41:18 +0000 |
| commit | c213db91bab640dd3c31c3366a07c29862ed8d2f (patch) | |
| tree | 99ff1332667474be1e22d3997cff771a4203f533 | |
| parent | e58b77de1c209274df7e006470f2629bc5a914a5 (diff) | |
Teach json serialization to serialize Decimal values
This is needed in newer versions of python (which may still have other
issues, but fix this one as it showed up now).
| -rw-r--r-- | postgresqleu/util/jsonutil.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/postgresqleu/util/jsonutil.py b/postgresqleu/util/jsonutil.py index 4a3e641a..9ba4eecb 100644 --- a/postgresqleu/util/jsonutil.py +++ b/postgresqleu/util/jsonutil.py @@ -1,4 +1,5 @@ from datetime import datetime, date +from decimal import Decimal import json @@ -6,6 +7,8 @@ class JsonSerializer(json.JSONEncoder): def default(self, obj): if isinstance(obj, datetime) or isinstance(obj, date): return obj.isoformat() + if isinstance(obj, Decimal): + return str(obj) if hasattr(obj, 'json_included_attributes'): return dict([(k, getattr(obj, k)) for k in obj.json_included_attributes]) return json.JSONEncoder.default(self, obj) |
