# class ItemSerializerPlugin

### abstract

Module | akonadi
Namespace | Akonadi
Class | ItemSerializerPlugin
Inherits |

Base class for PIM item type serializer plugins. Serializer plugins convert between the payload of Akonadi.Item objects and a textual or binary representation of the actual content data. This allows to easily add support for new types to Akonadi.

#### How to write an Akonadi serializer plugin

The following describes the basic steps needed to write an Akonadi serializer plugin.

##### (de-)Serialization Code

Create a class that inherits Akonadi.ItemSerializerPlugin and implement its two pure virtual methods, serialize() and deserialize().

##### Plugin Framework

To do: Factory macro

To do: Desktop file example

### methods

- deserialize (item, label, data, version)

  returns bool
  pure virtual

  Argument | Type | Default
  --- | --- | ---
  item | Akonadi.Item |
  label | QByteArray |
  data | QIODevice |
  version | int |

  Convert serialized item data provided in data into payload for item.

  item - The item to which the payload should be added. It is guaranteed to have a mimetype matching one of the supported mimetypes of this plugin. However it might contain a unsuited payload added manually by the application developer. Verifying the payload type in case a payload is already available is recommended therefore.

  label - The part identifier of the part to deserialize. label might be an unsupported item part, return false if this is the case.

  data - A QIODevice providing access to the serialized data. The QIODevice is opened in read-only mode and positioned at the beginning. The QIODevice is guaranteed to be valid. Returns false if the specified part is not supported by this plugin, true if the part could be de-serialized successfully.

- parts (item)

  returns QSet<QByteArray>

  Argument | Type | Default
  --- | --- | ---
  item | Akonadi.Item |

  Returns a list of available parts for the given item payload. The default implementation returns Item.FullPayload if a payload is set.

  item - The item.

- serialize (item, label, data, version)

  returns Nothing
  pure virtual

  Argument | Type | Default
  --- | --- | ---
  item | Akonadi.Item |
  label | QByteArray |
  data | QIODevice |
  version | int |

  Convert the payload object provided in item into its serialzed form into data.

  item - The item which contains the payload. It is guaranteed to have a mimetype matching one of the supported mimetypes of this plugin as well as the existence of a payload object. However it might contain an unsupported payload added manually by the application developer. Verifying the payload type is recommended therefore.

  label - The part identifier of the part to serialize. label will be one of the item parts returned by parts().

  data - The QIODevice where the serialized data should be writtne to. The QIODevice is opened in write-only mode and positioned at the beginning. The QIODevice is guaranteed to be valid.