add pathlib.Path serializer (#3082)

This commit is contained in:
Thomas Brandého 2024-04-13 01:27:10 +02:00 committed by GitHub
parent 3c8c7c3c46
commit b8525261b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,6 +7,7 @@ import types as builtin_types
import warnings
from datetime import date, datetime, time, timedelta
from enum import Enum
from pathlib import Path
from typing import Any, Callable, Dict, List, Set, Tuple, Type, Union, get_type_hints
from reflex.base import Base
@ -233,6 +234,19 @@ def serialize_datetime(dt: Union[date, datetime, time, timedelta]) -> str:
return str(dt)
@serializer
def serialize_path(path: Path):
"""Serialize a pathlib.Path to a JSON string.
Args:
path: The path to serialize.
Returns:
The serialized path.
"""
return str(path.as_posix())
@serializer
def serialize_enum(en: Enum) -> str:
"""Serialize a enum to a JSON string.