Fix: Better JSONification of pydantic models
Context
When building props, Pydantic models were converted to dict using Pydantic's model_dump
method, which converts the model to a dict.
When an Inertia call was made, a simple JSONResponse
(FastAPI's one) was returned, with the props.
However, JSONResponse does not handle some fields, such as datetime
, and would require either:
- Handling those prior to passing the models to the
render
method of inertia - Overriding the
render
method of inertia in order to use a customJSONResponse
which would handle those cases
This is very unoptimal.
Solution
-
Instead of using Pydantic's
model_dump
method, use itsmodel_dump_json
method which handles much more types, and usejson.loads
to convert it back to a dict. -
Expose a
_render_json
method so it can be easily overridden, without having to override the wholerender
method.