Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to parse createdAt and updatedAt fields when parse object sent as response from cloud code method #130

Closed
aceankur opened this issue Sep 13, 2015 · 13 comments

Comments

@aceankur
Copy link

This is specific to how android sdk is parsing the response from cloud code deployed by latest jssdk (1.6.0)
We have written a cloud code method which takes an id, creates an object and returns it. The response has createdAt is a json object with iso and type props:

{
    "result": {
        "__type": "Object",
        "className": "GameTable",
        "createdAt": {
            "__type": "Date",
            "iso": "2015-09-13T12:45:14.656Z"
        },
        "gamers": [],
        "initiator": null,
        "objectId": "p2Bz0c8jaq",
        "olock": 0,
        "status": "CREATED",
        "token": 7751,
        "updatedAt": {
            "__type": "Date",
            "iso": "2015-09-13T12:45:14.656Z"
        }
    }
}

We get a java.text.ParseException in callback for callFunctionInBackground method. When we switch parse jssdk to 1.5.0 and redeploy, this exception goes away in the Android code.

RCA from our end:

Since "__type": "Object" in the result, ParseDecoder.java calls fromJSON for the entire object, and ParseDateFormat receives { "__type": "Date", "iso": "2015-09-13T12:45:14.656Z" } which it is unable to parse and throws the exception.
After changing jssdk to 1.5.0, createdAt in the response from server was: "createdAt": "2015-09-13T12:45:14.656Z" (note: not a nested object anymore) and ParseDateFormat was able to parse this to a valid Date object.

@aceankur aceankur changed the title Unable to parse created_at and updated_at fields when parse object sent as response from cloud code method Unable to parse createdAt and updatedAt fields when parse object sent as response from cloud code method Sep 13, 2015
@grantland
Copy link
Contributor

Thanks for your detailed report! We've determined this is a bug in the latest JS SDK and are working on a fix.

The best workaround would be to revert to 1.5.0 for now as you've discovered.

@grantland
Copy link
Contributor

@andrewi Since JS isn't open sourced yet, mind being the assignee of this issue?

@andrewimm
Copy link

Resolved in the JS SDK codebase. I will attempt to release 1.6.2 today after a few more bugfixes.

@aceankur once the new version of the JS SDK has been released, you can update which version your cloud code uses in your config/global.json file.

@aceankur
Copy link
Author

Thanks @andrewimm. That was prompt.

@MariaKulkova
Copy link

@andrewimm you wrote that this bug had been resolved in release 1.6.2. But it isn't resolved now. Date in respons is still in UTC format.

@andrewimm
Copy link

@MariaKulkova can you be more specific about your issue? The response should be in UTC format, but it should be a string.
You can check in the Cloud Code tab of your Parse.com dashboard to see which version of the JS SDK is being used for your cloud functions.

@aceankur 1.6.2 was deployed last night, update your global.json and you should be fine. Sorry about that hiccup.

@MariaKulkova
Copy link

@andrewimm First of all, I'm sorry, I realized that the bug which was discussed in this theme doesn't completely match to my bug. But my bug is still isn't resolved.
I get a date string parsing exception while Parse iOS SDK tries to convert createdAt and updatedAt fields to NSDate when parse object is sent as response from Cloud code method. These dates must be represented in ISO format ("2015-09-14T15:18:01.521Z"), but they are returned from cloud code simply in UTC format ("2015-09-14 15:18:03 +0000"). Parse iOS SDK can't parse them and throws exception. I assume that this problem is connected with a way JS sdk converts dates to strings. Am I right?

@grantland
Copy link
Contributor

Closing this since the original issue has been resolved in the JS SDK release 1.6.2.

@MariaKulkova If you're still having issues, I recommend moving this conversation to the Parse-SDK-JS repository.

@d370urn3ur
Copy link

this is still not working for me. I am on JS SDK 1.6.2 and Android SDK 1.10.2 and i get the "getTime() on null object reference" error every time I call my cloud code function. Response format hasn't changed from @aceankur's original post: "createdAt":{"__type":"Date","iso":"2015-09-24T09:39:21.972Z"}, seems like Android SDK is expecting "createdAt":"2015-09-24T09:39:21.972Z".

@aceankur
Copy link
Author

@d370urn3ur I am still sticking with 1.5.0 SDK and have not verified the fix. This issue has been marked as closed. I suggest that you either get it reopened or create a new one to get visibility with parse developers.

@apersaud
Copy link

Anyway we can reopen this issue and have Android support both the string and hash version of Dates? Both the string and hash version of createdAt and updatedAt is supported in the iOS SDK and it is a bit inconsistent to have Date columns return hash versions while createdAt and updatedAt return strings. We are working on our cloud code webhooks server (that runs our cloud functions), and would be great to use the new common format across all platforms. Thanks!

@grantland
Copy link
Contributor

@apersaud We won't be reopening this issue since you're feature request is a bit different than the original bug report.

RE supporting JSON date formats in created/updatedAt: I'm not sure something like this would be necessary, since you shouldn't be modifying these values before the client receives them. If you're still interesting in pursuing this, I'd recommend opening a new issue.

@micaelomota
Copy link

I've got the error here trying to cache an object. If you do

const cacheString = JSON.stringify(parseObject.toJSON());
const obj = new Parse.Object.Extend('Player');
obj.set(JSON.parse(cacheString));
console.log(obj.toJSON());

you will see that the createdAt and updatedAt is not set properly.
Tested versions:

"parse": "^1.8.5",
"parse-server": "3.9.0",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants