MCPcopy
hub / github.com/marshmallow-code/marshmallow / dump

Method dump

src/marshmallow/schema.py:548–579  ·  view source on GitHub ↗

Serialize an object to native Python data types according to this Schema's fields. :param obj: The object to serialize. :param many: Whether to serialize `obj` as a collection. If `None`, the value for `self.many` is used. :return: Serialized data

(self, obj: typing.Any, *, many: bool | None = None)

Source from the content-addressed store, hash-verified

546 return ret
547
548 def dump(self, obj: typing.Any, *, many: bool | None = None):
549 """Serialize an object to native Python data types according to this
550 Schema's fields.
551
552 :param obj: The object to serialize.
553 :param many: Whether to serialize `obj` as a collection. If `None`, the value
554 for `self.many` is used.
555 :return: Serialized data
556
557 .. versionchanged:: 3.0.0b7
558 This method returns the serialized data rather than a ``(data, errors)`` tuple.
559 A :exc:`ValidationError <marshmallow.exceptions.ValidationError>` is raised
560 if ``obj`` is invalid.
561 .. versionchanged:: 3.0.0rc9
562 Validation no longer occurs upon serialization.
563 """
564 many = self.many if many is None else bool(many)
565 if self._hooks[PRE_DUMP]:
566 processed_obj = self._invoke_dump_processors(
567 PRE_DUMP, obj, many=many, original_data=obj
568 )
569 else:
570 processed_obj = obj
571
572 result = self._serialize(processed_obj, many=many)
573
574 if self._hooks[POST_DUMP]:
575 result = self._invoke_dump_processors(
576 POST_DUMP, result, many=many, original_data=obj
577 )
578
579 return result
580
581 def dumps(self, obj: typing.Any, *args, many: bool | None = None, **kwargs):
582 """Same as :meth:`dump`, except return a JSON-encoded string.

Calls 2

_serializeMethod · 0.95