Module: tastypie/lib/serializer

Provides standard data serialization & deserialization functionality


new (require("tastypie/lib/serializer"))( [options])

Parameters:
Name Type Argument Description
options Object <optional>

Serializer instance options options

Properties
Name Type Argument Default Description
callbackKey String <optional>
callback

callback key to be used for jsop responsed

defaultFormat String <optional>
'application/json'

the default serialziion format if one is not specified

xml Object <optional>

configuration objects for xml serialization vis xml2js

Properties
Name Type Argument Default Description
strict Boolean <optional>
false

if set to true, arrays will be serialize as a repeating elements with the same tag name.
When set to false, arrays are serialized as an object of type array with repeating elements

content_types Object <optional>

A mapping of Content Type header names to short formats ie { 'text/xml': 'xml' }

Source:
Tutorials:
Examples
serializer = new require("tastypie/lib/serializer")();
serializer.serialize({key:value}, "text/xml", null, console.log );
// define new acceptable content types & formats
FakeSerializer = new tastypie.Class({
     inherits:Serializer
     ,options:{
         content_types:{
             'application/vnd+fakescript':['fake', 'vnd-fake']
         }
     }

     ,constructor: function( options ){
         this.setOptions( options )
     }
     ,to_fake: function(data, callback){ ... }
     ,from_fake:function(data,callback){ ... }
});
// ?format=fake

Requires

Methods


deserialize(Data, contentType, callback)

Converts a data string into a javascript object based on a specified content type

Parameters:
Name Type Description
Data String

string to convert into an object

contentType String

the content type of the string to be deserialzie

callback function

a function to call when deserialization is complete

Source:

from_json(json, callback)

Converts a json string into an object

Parameters:
Name Type Description
json String

valid json string to parse into an object

callback function

callback function to call when deserialization is complete

Source:

from_xml(xml, callback)

converts an xml string into an object

Parameters:
Name Type Description
xml String

valid xml string to parse into an object

callback function

callback function to call when deserialization is complete

Source:

serialize(data, format, callback)

Serialized an object into a string of a specified format

Parameters:
Name Type Description
data Object

The data object to be serialized into a string

format String

The format to serialize the object down to

callback function

A callback function to be called when serialization is complete

Source:
Throws:

SerializationError


to_json(json, callback)

Converts an object into a valid JSON string

Parameters:
Name Type Description
json String

valid json string to parse into an object

callback function

callback function to call when deserialization is complete

Source:

to_jsonp(data, callback)

Converts an object in to a jsonp string

Parameters:
Name Type Description
data Object

data object to serialzie

callback function

a callback function to call when serialization is complete. Must accept an error object and data payload

Source:

to_xml(data, callback)

Converts an object to an xml string

Parameters:
Name Type Description
data String

object to convert into an xml string

callback function

callback function to call when deserialization is complete

Source: