Browse Source

Custom encoder for json dump

master
Marc Poulhiès 4 years ago
parent
commit
74d0552d0b
  1. 13
      jy901/json.py

13
jy901/json.py

@ -2,11 +2,18 @@ import json
import numpy as np
from .frames import *
import numpy as np
class JSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, AccelFrame):
print("boom")
return None
# if hasattr(obj, '__json__'):
# return obj.__json__()
# return json.JSONEncoder.default(self, obj)
if isinstance(obj, (AccelFrame, AngleFrame, MagneticFrame, AtmosphericFrame, AngularVelocityFrame)):
return obj.__dict__
elif isinstance(obj, np.ndarray):
return list(obj)
elif isinstance(obj, bytearray):
return [int(x) for x in obj]
return json.JSONEncoder.default(self, obj)

Loading…
Cancel
Save