`orderedstuf` not JSON-serializable
Issue #7
new
>>> from stuf import orderedstuf
>>> from collections import OrderedDict
>>> import json
>>> o = orderedstuf()
>>> o.a = 1
>>> o.b = 2
>>> o.c = 3
>>> o.d = 4
>>> o
orderedstuf(a=1, b=2, c=3, d=4)
>>> json.dumps(o)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 243, in dumps
return _default_encoder.encode(obj)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 207, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 270, in iterencode
return _iterencode(o, 0)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 184, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: orderedstuf(a=1, b=2, c=3, d=4) is not JSON serializable
What?! Why not?!
There is, thankfully, a workaround:
>>> json.dumps(OrderedDict(o))
'{"a": 1, "b": 2, "c": 3, "d": 4}'
I just don't like having to call OrderedDict
wrappers to do what orderedstuf
should do on its own.