dash-extensions icon indicating copy to clipboard operation
dash-extensions copied to clipboard

Feature Request: Update BaseModelTransform to use TypeAdapter

Open vmlopezr opened this issue 5 months ago • 1 comments

Pydantic's TypeAdapter has dump_python/dump_json (to serialize) and validate_python/validate_json to validate the annotations.

At the moment the BaseModelTransform/SerializationTransform only supports annotating BaseModel or list[BaseModel]. If we switch these to use TypeAdapter we could probably directly use TypeAdapter(annotation).validate_python (or validate_json) to also support validating/serializing annotations like dict[str, BaseModel], or more complicated types.

Thoughts on this suggestion? Happy to give it a attempt at a PR depending on feedback

vmlopezr avatar Jul 15 '25 02:07 vmlopezr

I think that sounds like a great idea. As I understand, the resulting solution would be backward compatible, but more powerful/general?

emilhe avatar Aug 06 '25 07:08 emilhe