ska_oso_pdm.schemas.codec

The codec module contains classes used by clients to marshall PDM classes to and from JSON. This saves the clients having to instantiate and manipulate the Marshmallow schema directly.

class MarshmallowCodec[source]

MarshmallowCodec marshalls and unmarshalls PDM classes.

The mapping of PDM classes to Marshmallow schema is defined in this class.

dumps(obj)[source]

Return a string JSON representation of a PDM instance.

Parameters:

obj – the instance to marshall to JSON

Returns:

a JSON string

load_from_file(cls, path)[source]

Load an instance of a PDM class from disk.

Parameters:
  • cls – the class to create from the file

  • path – the path to the file

Returns:

an instance of cls

loads(pdm_class, json_data)[source]

Create an instance of a PDM class from a JSON string.

Parameters:
  • pdm_class – the class to create from the JSON

  • json_data – the JSON to unmarshall

Returns:

an instance of cls

register_mapping(pdm_class)[source]

A decorator that is used to register the mapping between a Marshmallow schema and the PDM class it serialises.

Parameters:

pdm_class – the PDM class this schema maps to

set_schema(pdm_class, schema_class)[source]

Set the schema for a PDM class.

Parameters:
  • schema_class – Marshmallow schema to map

  • pdm_class – PDM class the schema maps to