Highlighted

CF 2016: serializeJson dies on CFC with null values

New Here ,
Aug 24, 2017

Copy link to clipboard

Copied

When serializing an object with a null or "undefined value" property (at least when it's a date), serializeJson dies trying to format the null date.

'' is not a valid date/time format.

----------------

component displayName="Order" accessors="true" {

     property name="orderNumber" type="string"

     property name="dateOrdered" type="date"

}

...

var order = new Order();

order.setOrderNumber("12345");

serializeJson(order);  // BOOM!

---------------------

In the past, null/undefined values would be excluded from the serialization -- and that's exactly what I want.

Is this just the way it is now?! Or is there something else I can do?

Views

395

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

CF 2016: serializeJson dies on CFC with null values

New Here ,
Aug 24, 2017

Copy link to clipboard

Copied

When serializing an object with a null or "undefined value" property (at least when it's a date), serializeJson dies trying to format the null date.

'' is not a valid date/time format.

----------------

component displayName="Order" accessors="true" {

     property name="orderNumber" type="string"

     property name="dateOrdered" type="date"

}

...

var order = new Order();

order.setOrderNumber("12345");

serializeJson(order);  // BOOM!

---------------------

In the past, null/undefined values would be excluded from the serialization -- and that's exactly what I want.

Is this just the way it is now?! Or is there something else I can do?

Views

396

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 24, 2017 0
BKBK LATEST
Adobe Community Professional ,
Aug 25, 2017

Copy link to clipboard

Copied

It should work. It did when I tested it.

order.cfc

component displayName="Order" accessors="true" {

     // Note semicolons!

     property name="orderNumber" type="string";

     property name="dateOrdered" type="date";

}

test.cfm

<cfscript>

order = new order();

order.setOrderNumber("12345");

writeoutput(serializeJson(order)); 

</cfscript>

When I run the above code in ColdFusion 2016, the result is:

{"orderNumber":"12345"}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 25, 2017 0