Skip to content

How do I properly serialize Parse Objects in cloudcode BeforeSave? #3363

@jeacott1

Description

@jeacott1

if I have a Numeric field and increment it using the sdk something like

...
someTestClassQuery.find().then(function(results) {
 results[0].increment("MyNumericField");
 results[0].save();

and I have cloudcode something like:

Parse.Cloud.beforeSave("TestClass", function(request, response) {

var fieldValue=req.object.get('MyNumericField'); //this holds the expected field value, already incremented.

  var jsonBody = {};
  jsonBody.object = req.object.toJSON();
  jsonBody.object.className = req.object.className;

/*at this point,  jsonBody.object has lost its actual current value, and its replaced by an IncrementOp with a value of 1.

var unmarshalled = JSON.parse(jsonBody.object);
this object is not the same as  req.object. 
var fieldValueb=req.object.get('MyNumericField'); returns IncrementOp, not value
*/

how should I properly marshall/unmarshall parse objects such that they maintain their integrity?

thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions