I am using CF11 with ORM and service layer to return ORM objects. My Angular app requires that JSON dates be returned in one of the two following formats:
'yyyy/MM/dd' (i.e., '2014/08/25')
'yyyy/MM/dd HH:mm:ss' (i.e., '2014/08/25 16:35:10')
My service CFC returns an array of objects as a JSON string, but Coldfusion serializes the dates in a string format like this: April, 21 2016 04:45:56
. This seems to be a result of the SerializeJson() function that is called under the hood.
Is there a way to have an ORM CFC return a date object in a specific JSON string format? As a workaround I created a new property called startTimeAsJson that returns a string using a getter function. But I’d prefer to find a way to have CF just serialize the date object with the format I want.
Here is my ORM object.
component persistent="true" table="course" accessors="true"
{
property name="startTime" column="start_time" type="date" ormtype="timestamp" notnull="false";
}
My service layer object.
component output="false" hint="CFBuilder-Generated:test_date"
{
remote orm.course[] function getAllCourses(string SortColumn = "STARTDATE DESC")
{
return entityLoad("course", {}, arguments.sortcolumn);
}
}
An example of the JSON returned by my service CFC.
[{"startTime":"May, 09 2016 08:25:24"}]