SerializableObjectJson
Base class for objects that can be serialized to and from JSON.
SerializableObjectJson defines the interface for custom objects that need to be stored in RFields. Objects must implement both serialize and deserialize methods to convert between Python objects and JSON-compatible representations.
This is useful when: - You need custom serialization logic not covered by Pydantic - You want fine-grained control over the serialization format - You're working with complex objects that need special handling - You want to maintain backward compatibility with existing formats
The serialization must produce JSON-compatible types (dict, list, str, bool, float, int, None), which can be stored and later deserialized back to the original object.
Example: ```python class Point(SerializableObjectJson): def init(self, x: float, y: float): self.x = x self.y = y
def serialize(self) -> Dict:
return {'x': self.x, 'y': self.y}
@classmethod
def deserialize(cls, data: Dict) -> 'Point':
return cls(x=data['x'], y=data['y'])
class MyResource(Resource):
location = SerializableRField(object_type=Point)
```
Serialize this object to a JSON-compatible representation.
This method is called when the Resource containing this object is saved. It must return a JSON-compatible type (dict, list, str, bool, float, int, None) that can be deserialized back to the object later.
dict | list | str | bool | floatDeserialize a JSON-compatible representation back to an object instance.
This class method is called when the Resource is loaded from storage. It must reconstruct the object from the data produced by the serialize method.
dict | list | str | bool | floatSerializableObjectJson