Skip to content

JSON

cachetory.serializers.JsonSerializer

Uses the standard built-in json serialization.

Source code in cachetory/serializers/json.py
class JsonSerializer(Serializer[ValueT, str], Generic[ValueT]):
    """
    Uses the standard built-in [`json`][1] serialization.

    [1]: https://docs.python.org/3/library/json.html
    """

    @classmethod
    def from_url(cls, url: str) -> JsonSerializer[ValueT]:
        """
        Construct serializer from the URL.

        # Supported schema's

        - `json://`
        """
        return JsonSerializer[ValueT]()

    def serialize(self, value: ValueT) -> str:
        return json.dumps(value)

    def deserialize(self, data: str) -> ValueT:
        return json.loads(data)  # type: ignore[no-any-return]

from_url classmethod

from_url(url: str) -> JsonSerializer[ValueT]

Construct serializer from the URL.

Supported schema's

  • json://
Source code in cachetory/serializers/json.py
@classmethod
def from_url(cls, url: str) -> JsonSerializer[ValueT]:
    """
    Construct serializer from the URL.

    # Supported schema's

    - `json://`
    """
    return JsonSerializer[ValueT]()