Serializing and Deserializing Data

In CFML, the process of serializing and deserializing data is handled by the CFWDDX tag. The following sections step through the process of using the tag to serialize and deserialize various simple and complex datatypes. Numerous examples are provided to make the concepts as clear as possible.

Serializing and Deserializing Simple Values

The easiest types of values to work with are simple values, as simple values only consist of numbers, strings, Boolean, date/time values, and null datatypes. The process of serializing and deserializing simple values then is straightforward. Example 20-1 serializes an example of each simple datatype (boolean, dateTime, null, number, and string) and displays the resulting WDDX packets in an HTML table so that you can see how the structure of each packet varies depending on the datatype represented.

Example 20-1. Serializing Simple Datatypes to WDDX

<!--- serialize a boolean ---> <CFWDDX ACTION="CFML2WDDX" INPUT="#IsDefined('y')#" OUTPUT="WDDX_boolean"> <!--- serialize a dateTime ---> <CFWDDX ACTION="CFML2WDDX" INPUT="#now( )#" OUTPUT="WDDX_dateTime" USETIMEZONEINFO="Yes"> <!--- serialize a number ---> <CFWDDX ACTION="CFML2WDDX" INPUT="#Val(123.456)#" OUTPUT="WDDX_Number"> <!--- serialize a null ColdFusion style (an empty string) ---> <CFWDDX ACTION="CFML2WDDX" INPUT="" OUTPUT="WDDX_Null"> <!--- serialize a string ---> <CFWDDX ACTION="CFML2WDDX" INPUT="I am a string!" OUTPUT="WDDX_String1"> <!--- serialize a string ...

Get Programming ColdFusion now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.