add pathlib.Path serializer (#3082)
This commit is contained in:
parent
3c8c7c3c46
commit
b8525261b5
@ -7,6 +7,7 @@ import types as builtin_types
|
|||||||
import warnings
|
import warnings
|
||||||
from datetime import date, datetime, time, timedelta
|
from datetime import date, datetime, time, timedelta
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
from pathlib import Path
|
||||||
from typing import Any, Callable, Dict, List, Set, Tuple, Type, Union, get_type_hints
|
from typing import Any, Callable, Dict, List, Set, Tuple, Type, Union, get_type_hints
|
||||||
|
|
||||||
from reflex.base import Base
|
from reflex.base import Base
|
||||||
@ -233,6 +234,19 @@ def serialize_datetime(dt: Union[date, datetime, time, timedelta]) -> str:
|
|||||||
return str(dt)
|
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
|
@serializer
|
||||||
def serialize_enum(en: Enum) -> str:
|
def serialize_enum(en: Enum) -> str:
|
||||||
"""Serialize a enum to a JSON string.
|
"""Serialize a enum to a JSON string.
|
||||||
|
Loading…
Reference in New Issue
Block a user