lovasoa / marshmallow_dataclass

Automatic generation of marshmallow schemas from dataclasses.
https://lovasoa.github.io/marshmallow_dataclass/html/marshmallow_dataclass.html
MIT License
458 stars 78 forks source link

Add .load_to_dict method to base schema #213

Open dairiki opened 2 years ago

dairiki commented 2 years ago

Following up on this suggestion made in a comment on #169 (see also #210), this provides a new schema method, .load_to_mapping, that essentially does a raw marshmallow.Schema.load without converting any of the deserialized values (either top-level or nested) to dataclasses. The main point of this is to allow for deserializing partial data (with partial=True).

This PR is provided for discussion, as to:

lovasoa commented 2 years ago

I'm ok with that ! Maybe load_to_dict is clearer than load_to_mapping ? Doesn't it always return a dict ?

dairiki commented 2 years ago

I'm ok with that ! Maybe load_to_dict is clearer than load_to_mapping ? Doesn't it always return a dict ?

Yes, that's probably better.

After some digging through the marshmallow source code it appears to always return dict (or OrderedDict) (or a list of those if many is set). I will rename it.