The class can serialize itself by adding a method called `to_json` or by providing a `to_dict` method to be called before serialization.