Menu
Introduction
Getting Started
Developer guide
Release
Architecture
CLI
Technical documentations
Version
Publication date

Mar 9, 2022

Confidentiality
Public
Reactions
1
Share

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)
```
Functions
serialize

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.

Return type : dict | list | str | bool | float
deserialize @classmethod

Deserialize 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.

data : dict | list | str | bool | float
JSON-compatible data produced by the serialize method
Return type : SerializableObjectJson
Shine Logo
Technical bricks to reuse or customize

Have you developed a brick?

Share it to accelerate projects for the entire community.