tracker issue : CF-4202393

select a category, or use search below
(searches all categories and all time range)
Title:

[ANeff] ER for: THIS.serialization.preserveDateTime

| View in Tracker

Status/Resolution/Reason: Needs Review//

Reporter/Name(from Bugbase): Aaron Neff / ()

Created: 05/11/2018

Components: Language, Serialization

Versions: 2018

Failure Type: Others

Found In Build/Fixed In Build: /

Priority/Frequency: Normal /

Locale/System: / Platforms All

Vote Count: 0

Issue: Currently JSON serialization+deserialization converts DateTime to String without UTC offset

Steps to Reproduce:

1) Run:

<cfscript>
  myDateTime = createDate(2018,1,1)
  myDateTimeJSON = serializeJSON(myDateTime)
  writeOutput(myDateTime.dateTimeFormat("iso") & '<br>' & myDateTimeJSON)
</cfscript>

Actual Result (depending on time zone):
2018-01-01T00:00:00-05:00
"January, 01 2018 00:00:00"

Expected Result (depending on time zone):
2018-01-01T00:00:00-05:00
2018-01-01T00:00:00-05:00

See? JSON serialization causes data loss by dropping the UTC offset.

2) Run:

<cfscript>
  myDateTime = createDate(2018,1,1)
  myVar = {myDateTime=myDateTime, myQuery=queryNew("myDateTime", "timestamp", [[myDateTime]])}
  afterJSON = deserializeJSON(serializeJSON(myVar), false)
  writeOutput(myVar.myDateTime.getClass().getName() & '<br>' & myVar.myQuery.myDateTime[1].getClass().getName() & '<br>' & afterJSON.myDateTime.getClass().getName() & '<br>' & afterJSON.myQuery.myDateTime[1].getClass().getName())
</cfscript>

Actual Result:
coldfusion.runtime.OleDateTime
java.sql.Timestamp
java.lang.String
java.lang.String

Expected Result:
coldfusion.runtime.OleDateTime
java.sql.Timestamp
coldfusion.runtime.OleDateTime
java.sql.Timestamp

See? JSON serialization+deserialization converts DateTime to String

Suggestion: THIS.serialization.preserveDateTime to provide correct behavior for #1 and #2

Attachments:

Comments:

Related thread: https://forums.adobeprerelease.com/coldfusionpr/discussion/391/cf-4202393-this-serialization-preservedatetime
Comment by Aaron N.
27755 | May 11, 2018 08:47:31 PM GMT
Hi Adobe, Regarding #1: The correct solution would be to fix JSON serialization of DateTime to store in a standardized (ISO8601) format. Regarding #2: `DeserializeJSON()` already has a `strictMapping` parameter that "specifies whether to convert the JSON strictly". When false, it converts certain string patterns to CF query objects. It could be enhanced to also convert ISO8601 string patterns to CF DateTime objects. Since both of those solutions would break backward-compat, this ER is for: THIS.serialization.preserveDateTime. Thanks!, -Aaron
Comment by Aaron N.
27756 | May 11, 2018 09:18:59 PM GMT