New submission from andrew c <achapkow...@esri.com>:
When creating a custom class that doesn't inherit from the accepted classes, there is no way to serialize it using json.dumps or json.dump. I propose that __fromjson__ and __tojson__ that when present will be used by the Python's default encoder. This issue is widely documented on stackoverflow as a deficiency. You basically have a couple of options to solve this: 1. Implement a custom json.JSONEncoder/json.JSONDecoder 2. Implement a method like to/from json 3. Monkey patch the json library 4. Use a 3rd party library These are not very good options. If you can serialize an object using pickle, why not have the ability to serialize objects using json? Thank you ---------- messages: 328897 nosy: andrewchap priority: normal severity: normal status: open title: Make Custom Object Classes JSON Serializable type: enhancement versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35111> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com