Skip to content

Bulk asynchronous downloader for multiple file hosts

fix: `yarl.URL` json serialization (#605)

NTFSvolumefcc3f17ea850
diff --git a/cyberdrop_dl/config_definitions/pydantic/custom_types.py b/cyberdrop_dl/config_definitions/pydantic/custom_types.py
index 168d48a97..dd326dea9 100644
--- a/cyberdrop_dl/config_definitions/pydantic/custom_types.py
+++ b/cyberdrop_dl/config_definitions/pydantic/custom_types.py
@@ -8,6 +8,7 @@ from pydantic import (
BaseModel,
ConfigDict,
HttpUrl,
+ PlainSerializer,
Secret,
SerializationInfo,
StringConstraints,
@@ -21,9 +22,11 @@ def convert_to_yarl(value: AnyUrl) -> URL:
return URL(str(value))
-HttpURL = Annotated[HttpUrl, AfterValidator(convert_to_yarl)]
+StrSerializer = PlainSerializer(str, return_type=str, when_used="json-unless-none")
+
+HttpURL = Annotated[HttpUrl, AfterValidator(convert_to_yarl), StrSerializer]
NonEmptyStr = Annotated[str, StringConstraints(min_length=1, strip_whitespace=True)]
-AnyURL = Annotated[AnyUrl, AfterValidator(convert_to_yarl)]
+AnyURL = Annotated[AnyUrl, AfterValidator(convert_to_yarl), StrSerializer]
SecretAnyURL = Secret[AnyURL]
SecretHttpURL = Secret[HttpURL]