mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-06 02:21:42 +00:00
Fix a bug where some NaN values could leak into the JSON output, causing it to be invalid. Created a new safe_json_dumps method since we would otherwise now be providing multiple parameters all over the code
This commit is contained in:
+8
-5
@@ -1,8 +1,11 @@
|
||||
def serialize_everything(obj):
|
||||
"""Convert objects to serialisable things. Used by JSON serialiser as a default when it encounters unserializable things.
|
||||
Just converts objects to dict. Try to avoid doing anything clever here when serialising spots, because we also need
|
||||
to receive spots without complex handling."""
|
||||
return obj.__dict__
|
||||
import simplejson
|
||||
|
||||
|
||||
def safe_json_dumps(obj):
|
||||
"""Safe version of json.dumps that also converts objects to dicts so they can be output, and ignores NaN floats
|
||||
which are invalid in JSON."""
|
||||
|
||||
return simplejson.dumps(obj, ensure_ascii=False, ignore_nan=True, default=lambda o: o.__dict__)
|
||||
|
||||
|
||||
def empty_queue(q):
|
||||
|
||||
Reference in New Issue
Block a user