pydent.relationships.JSON

class pydent.relationships.JSON(many=False, data_key=None, allow_none=True, default=None)[source]

Bases: pydent.relationships.Raw

Automatically serializes/deserializes JSON objects.

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=False, data_key=None, allow_none=True, default=None)

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)

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