pydent.marshaller.fields.Field

class pydent.marshaller.fields.Field(many=None, data_key=None, allow_none=None, default=<Placeholders.DEFAULT: 4>)[source]

Bases: pydent.marshaller.fields.FieldABC

A serialization/deserialization field.

A standard field. Performs no functions on serialized and deserialized data.

Parameters
  • many (bool) – whether to treat serializations and deserializations as a per-item basis in a list

  • data_key (basestring) – the data_key, or attribute name, of this field. Calling this as an attribute to the registered nested should return this field’s descriptor.

  • allow_none (bool) – whether to return None if None is received in deserialization or serializaiton methods

Raises

AllowNoneFieldValidationError if None is received in serialize and deserialized methods and self.allow_none == False

__init__(many=None, data_key=None, allow_none=None, default=<Placeholders.DEFAULT: 4>)[source]

A standard field. Performs no functions on serialized and deserialized data.

Parameters
  • many (bool) – whether to treat serializations and deserializations as a per-item basis in a list

  • data_key (basestring) – the data_key, or attribute name, of this field. Calling this as an attribute to the registered nested should return this field’s descriptor.

  • allow_none (bool) – whether to return None if None is received in deserialization or serializaiton methods

Raises

AllowNoneFieldValidationError if None is received in serialize and deserialized methods and self.allow_none == False

Methods

__init__([many, data_key, allow_none, default])

A standard field.

deserialize(owner, data)

rtype

Optional[dict]

register(name, objtype)

Registers the field to a nested class.

serialize(owner, data)

rtype

Union[dict, None, List]

set_data_key(key)

ACCESSOR

alias of pydent.marshaller.descriptors.MarshallingAccessor

register(name, objtype)[source]

Registers the field to a nested class. Instantiates the corresponding descriptor (i.e. accessor)

Parameters
  • name (str) – name of the field

  • objtype (Type) – the nested class to register the field to

Returns

None

Return type

None