Django Ninja doesn't use Pydantic's JSON serialization mode

Author: oliverhaasCreated Dec 11, 2025Updated May 24, 2026

When serializing one of my pydantic models which contained a set field, I was expecting django-ninja to do something like this internally

instance.model_dump(mode="json") # converts set → list, UUID → str, etc.

but what happens is rather something like (simplified!)

json.dumps(instance.model_dump(), cls=DjangoJSONEncoder) # set stays as set which can not be encoded further→ exception

Is there a specific reason for this? Even just making a small adjustment here https://github.com/vitalik/django-ninja/blob/9b7c4f122554dfb4a5959b0bf90b0c856d72cbed/ninja/responses.py#L24 to use .model_dump(mode="json") would probably address this error and similar ones.

Mainly asking because I was wondering whether I'm missing something, since going with pydantic's serialization seems like the way to go here. There are related issues possible (e.g. #247).