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
|
- 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
- module:xml2js
- module:jstoxml
- module:events
- module:util
- module:debug
- module:tastypie/lib/class
- module:tastypie/lib/class/options
- module:mout/lang/kindOf
- module:prim-util/prime/parentize
- module:mout/lang/isObject
- module:tastypie/lib/utility
- module:tastypie/lib/exceptions
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: