Repository: vitalik/django-ninja
Issue category: Bug Report

Issue:
[BUG] Object of type Url is not JSON serializable
**Describe the bug**
django-ninja = "^1.3.0"

Using `HttpUrl` (or, I suspect, any *Url class) for a schema used in a response results in json serialization error. This is the same type of issue as #717.

```pytb
Traceback (most recent call last):
  File "/home/adys/.cache/pypoetry/virtualenvs/fabrile-backend-fklT6p4J-py3.10/lib/python3.10/site-packages/ninja/operation.py", line 121, in run
    return self._result_to_response(request, result, temporal_response)
  File "/home/adys/.cache/pypoetry/virtualenvs/fabrile-backend-fklT6p4J-py3.10/lib/python3.10/site-packages/ninja/operation.py", line 278, in _result_to_response
    return self.api.create_response(
  File "/home/adys/.cache/pypoetry/virtualenvs/fabrile-backend-fklT6p4J-py3.10/lib/python3.10/site-packages/ninja/main.py", line 453, in create_response
    content = self.renderer.render(request, data, response_status=status)
  File "/home/adys/.cache/pypoetry/virtualenvs/fabrile-backend-fklT6p4J-py3.10/lib/python3.10/site-packages/ninja/renderers.py", line 25, in render
    return json.dumps(data, cls=self.encoder_class, **self.json_dumps_params)
  File "/usr/lib/python3.10/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/home/adys/.cache/pypoetry/virtualenvs/fabrile-backend-fklT6p4J-py3.10/lib/python3.10/site-packages/ninja/responses.py", line 28, in default
    return super().default(o)
  File "/home/adys/.cache/pypoetry/virtualenvs/fabrile-backend-fklT6p4J-py3.10/lib/python3.10/site-packages/django/core/serializers/json.py", line 106, in default
    return super().default(o)
  File "/usr/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Url is not JSON serializable
```


Hints:

Patch:
diff --git a/ninja/responses.py b/ninja/responses.py
index babd366e..6a0fd4ca 100644
--- a/ninja/responses.py
+++ b/ninja/responses.py
@@ -1,10 +1,11 @@
 from enum import Enum
-from ipaddress import IPv4Address, IPv6Address
+from ipaddress import IPv4Address, IPv4Network, IPv6Address, IPv6Network
 from typing import Any, FrozenSet
 
 from django.core.serializers.json import DjangoJSONEncoder
 from django.http import JsonResponse
 from pydantic import BaseModel
+from pydantic_core import Url
 
 __all__ = [
     "NinjaJSONEncoder",
@@ -21,7 +22,9 @@ class NinjaJSONEncoder(DjangoJSONEncoder):
     def default(self, o: Any) -> Any:
         if isinstance(o, BaseModel):
             return o.model_dump()
-        if isinstance(o, (IPv4Address, IPv6Address)):
+        if isinstance(o, Url):
+            return str(o)
+        if isinstance(o, (IPv4Address, IPv4Network, IPv6Address, IPv6Network)):
             return str(o)
         if isinstance(o, Enum):
             return str(o)


Test patch: