|
None | __init__ (self, *typing.Any default=missing_, typing.Any missing=missing_, typing.Optional[str] data_key=None, typing.Optional[str] attribute=None, typing.Optional[typing.Union[typing.Callable[[typing.Any], typing.Any], typing.Iterable[typing.Callable[[typing.Any], typing.Any]],]] validate=None, bool required=False, typing.Optional[bool] allow_none=None, bool load_only=False, bool dump_only=False, typing.Optional[typing.Dict[str, str]] error_messages=None, typing.Optional[typing.Mapping[str, typing.Any]] metadata=None, **additional_metadata) |
|
str | __repr__ (self) |
|
def | __deepcopy__ (self, memo) |
|
def | get_value (self, obj, attr, accessor=None, default=missing_) |
|
ValidationError | make_error (self, str key, **kwargs) |
|
def | fail (self, str key, **kwargs) |
|
def | serialize (self, str attr, typing.Any obj, typing.Optional[typing.Callable[[typing.Any, str, typing.Any], typing.Any]] accessor=None, **kwargs) |
|
def | deserialize (self, typing.Any value, typing.Optional[str] attr=None, typing.Optional[typing.Mapping[str, typing.Any]] data=None, **kwargs) |
|
def | context (self) |
|
def | serialize (self, attr, obj, accessor=None) |
|
def | deserialize (self, value) |
|
Basic field from which other fields should extend. It applies no
formatting by default, and should only be used in cases where
data does not need to be formatted before being serialized or deserialized.
On error, the name of the field will be returned.
:param default: If set, this value will be used during serialization if the input value
is missing. If not set, the field will be excluded from the serialized output if the
input value is missing. May be a value or a callable.
:param missing: Default deserialization value for the field if the field is not
found in the input data. May be a value or a callable.
:param data_key: The name of the dict key in the external representation, i.e.
the input of `load` and the output of `dump`.
If `None`, the key will match the name of the field.
:param attribute: The name of the attribute to get the value from when serializing.
If `None`, assumes the attribute has the same name as the field.
Note: This should only be used for very specific use cases such as
outputting multiple fields for a single attribute. In most cases,
you should use ``data_key`` instead.
:param validate: Validator or collection of validators that are called
during deserialization. Validator takes a field's input value as
its only parameter and returns a boolean.
If it returns `False`, an :exc:`ValidationError` is raised.
:param required: Raise a :exc:`ValidationError` if the field value
is not supplied during deserialization.
:param allow_none: Set this to `True` if `None` should be considered a valid value during
validation/deserialization. If ``missing=None`` and ``allow_none`` is unset,
will default to ``True``. Otherwise, the default is ``False``.
:param load_only: If `True` skip this field during serialization, otherwise
its value will be present in the serialized data.
:param dump_only: If `True` skip this field during deserialization, otherwise
its value will be present in the deserialized object. In the context of an
HTTP API, this effectively marks the field as "read-only".
:param dict error_messages: Overrides for `Field.default_error_messages`.
:param metadata: Extra information to be stored as field metadata.
.. versionchanged:: 2.0.0
Removed `error` parameter. Use ``error_messages`` instead.
.. versionchanged:: 2.0.0
Added `allow_none` parameter, which makes validation/deserialization of `None`
consistent across fields.
.. versionchanged:: 2.0.0
Added `load_only` and `dump_only` parameters, which allow field skipping
during the (de)serialization process.
.. versionchanged:: 2.0.0
Added `missing` parameter, which indicates the value for a field if the field
is not found during deserialization.
.. versionchanged:: 2.0.0
``default`` value is only used if explicitly set. Otherwise, missing values
inputs are excluded from serialized output.
.. versionchanged:: 3.0.0b8
Add ``data_key`` parameter for the specifying the key in the input and
output data. This parameter replaced both ``load_from`` and ``dump_to``.