Skip to content

JsonSerializer

Bases: Serializer[T]

Serializes with the standard library json module. obj must be JSON-serializable (dicts, lists, strings, numbers, bools, None).

Source code in src/alchemical_queues/serializers.py
47
48
49
50
51
52
53
54
55
class JsonSerializer(Serializer[T]):
    """Serializes with the standard library `json` module. `obj` must be
    JSON-serializable (dicts, lists, strings, numbers, bools, `None`)."""

    def dumps(self, obj: T) -> bytes:
        return json.dumps(obj).encode("utf-8")

    def loads(self, data: bytes) -> T:
        return json.loads(data.decode("utf-8"))