asphalt.serialization.serializers.json

class asphalt.serialization.serializers.json.JSONSerializer(encoder_options=None, decoder_options=None, encoding='utf-8', custom_type_codec=None)

Bases: CustomizableSerializer

Serializes objects using JSON (JavaScript Object Notation).

See the json module documentation in the standard library for more information on available options.

Certain options can resolve references to objects:

  • encoder_options['default']

  • decoder_options['object_hook']

  • decoder_options['object_pairs_hook']

Parameters:
  • encoder_options – keyword arguments passed to JSONEncoder

  • decoder_options – keyword arguments passed to JSONDecoder

  • encoding – the text encoding to use for converting to and from bytes

  • custom_type_codec – wrapper to use to wrap custom types after marshalling

deserialize(payload)

Deserialize bytes into a Python object.

Return type:

Any

property mimetype: str

Return the MIME type for this serialization format.

serialize(obj)

Serialize a Python object into bytes.

Return type:

bytes

class asphalt.serialization.serializers.json.JSONTypeCodec(type_key='__type__', state_key='state')

Bases: DefaultCustomTypeCodec[JSONSerializer]

Default state wrapper implementation for JSONSerializer.

register_object_decoder_hook(serializer)

Register a callback on the serializer for unmarshalling previously marshalled objects.

Parameters:

serializer (JSONSerializer) – the serializer instance to use

Return type:

None

register_object_encoder_hook(serializer)

Register a custom encoder callback on the serializer.

This callback would be called when the serializer encounters an object it cannot natively serialize. What the callback returns is specific to each serializer type.

Parameters:

serializer (JSONSerializer) – the serializer instance to use

Return type:

None