serialize

Serializes the object to a specified type

serialize( objToBeSerialized, type, useCustomSerializer ); → returns string

serialize Argument Reference

objToBeSerialized any
Required

An object to be serialized.

type string
Required

CF 11+ A type to which the object will be serialized. ColdFusion, by default supports XML and JSON formats. You can also implement support for other types in the CustomSerializer CFC.

useCustomSerializer boolean
Required
Default: true

CF 11+ Whether to use the custom serializer or not. The custom serializer will be always used for XML deserialization.
If false, the XML/JSON deserialization will be done using the default ColdFusion behavior.
If any other type is passed with useCustomSerializer as false, then TypeNotSupportedException will be thrown.

Examples sample code invoking the serialize function

Lucee 5+ This function will serialize the object to a specified type using ColdFusion's default serialization mechanism.

serialize({ "firstName": "John", "lastName": "Doe" });

Expected Result: {"lastName":"Doe","firstName":"John"}

CF 11+ This function will serialize the object to a specified type using ColdFusion's default serialization mechanism.

serialize({ "firstName": "John", "lastName": "Doe" }, 'json');

Expected Result: {"lastName":"Doe","firstName":"John"}


Fork me on GitHub