Hi,
the docs for the Encoder class say to raise a TypeError if it cannot return a JSON encodable version of value:
If implemented, this method is called whenever the serialization machinery finds a Python object that it does not recognize: if possible, the method should returns a JSON encodable version of the value, otherwise raise a TypeError
Yet, the example code provided raises a ValueError instead:
class PointEncoder(Encoder):
def default(self, obj):
if isinstance(obj, Point):
return {'x': obj.x, 'y': obj.y}
else:
raise ValueError('%r is not JSON serializable' % obj)
IMHO the example should return a TypeError to be consistent with the documentation.
Hi,
the docs for the Encoder class say to raise a
TypeErrorif it cannot return a JSON encodable version ofvalue:Yet, the example code provided raises a
ValueErrorinstead:IMHO the example should return a
TypeErrorto be consistent with the documentation.