[New-bugs-announce] [issue35111] Make Custom Object Classes JSON Serializable
andrew c
report at bugs.python.org
Tue Oct 30 07:43:02 EDT 2018
New submission from andrew c <achapkowski at 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 <report at bugs.python.org>
<https://bugs.python.org/issue35111>
_______________________________________
More information about the New-bugs-announce
mailing list