This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author andrewchap
Recipients andrewchap
Date 2018-10-30.11:43:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1540899782.53.0.788709270274.issue35111@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2018-10-30 11:43:02andrewchapsetrecipients: + andrewchap
2018-10-30 11:43:02andrewchapsetmessageid: <1540899782.53.0.788709270274.issue35111@psf.upfronthosting.co.za>
2018-10-30 11:43:02andrewchaplinkissue35111 messages
2018-10-30 11:43:02andrewchapcreate