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 DataString string to convert into an object
contentTypeString the content type of the string to be deserialzie
callbackfunction a function to call when deserialization is complete
- Source:
-
from_json(json, callback)
-
Converts a json string into an object
Parameters:
Name Type Description jsonString valid json string to parse into an object
callbackfunction callback function to call when deserialization is complete
- Source:
-
from_xml(xml, callback)
-
converts an xml string into an object
Parameters:
Name Type Description xmlString valid xml string to parse into an object
callbackfunction 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 dataObject The data object to be serialized into a string
formatString The format to serialize the object down to
callbackfunction 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 jsonString valid json string to parse into an object
callbackfunction 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 dataObject data object to serialzie
callbackfunction 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 dataString object to convert into an xml string
callbackfunction callback function to call when deserialization is complete
- Source: