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

Method _serialize

src/marshmallow/fields.py:416–436  ·  view source on GitHub ↗

Serializes ``value`` to a basic Python datatype. Noop by default. Concrete :class:`Field` classes should implement this method. Example: :: class TitleCase(Field): def _serialize(self, value, attr, obj, **kwargs): if not value:

(
        self, value: _InternalT | None, attr: str | None, obj: typing.Any, **kwargs
    )

Source from the content-addressed store, hash-verified

414 )
415
416 def _serialize(
417 self, value: _InternalT | None, attr: str | None, obj: typing.Any, **kwargs
418 ) -> typing.Any:
419 """Serializes ``value`` to a basic Python datatype. Noop by default.
420 Concrete :class:`Field` classes should implement this method.
421
422 Example: ::
423
424 class TitleCase(Field):
425 def _serialize(self, value, attr, obj, **kwargs):
426 if not value:
427 return ""
428 return str(value).title()
429
430 :param value: The value to be serialized.
431 :param attr: The attribute or key on the object to be serialized.
432 :param obj: The object the value was pulled from.
433 :param kwargs: Field-specific keyword arguments.
434 :return: The serialized value
435 """
436 return value
437
438 def _deserialize(
439 self,

Callers 1

serializeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected