How to make a class JSON serializable

Do you have an idea about the expected output? For example, will this do? In that case you can merely call json.dumps(f.__dict__). If you want more customized output then you will have to subclass JSONEncoder and implement your own custom serialization. For a trivial example, see below. Then you pass this class into the json.dumps() method as cls kwarg: If you also … Read more

What is a serialVersionUID and why should I use it?

The docs for java.io.Serializable are probably about as good an explanation as you’ll get: The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization. If … Read more