No activity today, make something!
tiddlyweb How do I use a serializer from plugin code?

20160313160645 cdent  

The following examples may be instructive. These examples assume the correct modules have been imported.

If you want to serialize a Tiddler object to JSON the code will look something like this, assuming {{{tiddler}}} is a fully populated tiddler object: {{{ serializer = Serializer('json') serializer.object = tiddler json_string = serializer.to_string() }}}

If you want to use a JSON string to populate a Tiddler object, you must first create an empty object and then fill it via the serializer: {{{ serializer = Serializer('json') tiddler = Tiddler(title) serializer.object = tiddler serializer.from_string(json_string) }}}

The situation is similar for other entities.

Note that the string argument that is passed to the {{{Serializer}}} class identifies a Python module. First the {{{tiddlyweb.serializations}}} package is searched for a matching module, and then {{{sys.path}}}. For non-core serializations, this means that the input to {{{Serializer}}} may be a dotted module identifier, such as {{{tiddlywebwiki.serialization}}}.

See also: serializer SerializationInterface