Dojo

DWR 3.0.2 jsonp and dates

#1

I have just updated DWR to 3.0.2 and set the jsonpEnabled parameter to true as I want to try that out (as part of a new section of functionality written using React).

Generally it works fine - a call to fetch a list of suppliers works and provides me with JSON to parse.

However when I fetch something which has a Date member then the json contains something like
{
“currentSeason”: “N”,
“openStatus”: “O”,
“seasonEndDate”: new Date(1543536000000),
“seasonId”: 14,
“seasonStartDate”: new Date(1512086400000),
},

As far as I am aware (according to ECMA-404) - new Date(xxx) is invalid in JSON.

So is there a work-round for this? Or a fix planned? The alternative I guess is to write my a function to manipulate the data, turning new Dates() into some other valid representation, then post-processing.

#2

Thanks for letting us know! Yes, the desired date format for JSON would be ISO 8601 strings. I’ve created an issue to fix this in the next release:

In the meantime to workaround your problem you can override DWR’s DateConverter with a version that outputs the desired format. You then register the new converter in the <init> section of dwr.xml, read more here:
http://directwebremoting.org/dwr/documentation/server/configuration/dwrxml/index.html