Permalink
Browse files

fixes issue #20, toJSON now allows for objects to have null values

  • Loading branch information...
1 parent 04869ee commit 99d8fd0ddd3dbc9c25ea2274a72c6456bbe34a19 @semmypurewal committed Oct 27, 2012
Showing with 19 additions and 19 deletions.
  1. +1 −1 build/jermaine-min.js
  2. +1 −9 build/jermaine.js
  3. +16 −0 spec/core/model.js
  4. +1 −9 src/core/model.js
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -894,25 +894,17 @@ window.jermaine.util.namespace("window.jermaine", function (ns) {
}
}
- if (attributeValue !== undefined && attributeValue.toJSON !== undefined && attributeJSONrep === null) {
+ if (attributeValue !== undefined && attributeValue !== null && attributeValue.toJSON !== undefined && attributeJSONrep === null) {
/* create a new entry for the attribute */
attributeJSONrep = (attributes[attributeList[i]] instanceof AttrList)?[]:{};
JSONreps.push({object:attributeValue, JSONrep:attributeJSONrep});
JSONreps[JSONreps.length-1].JSONrep = attributeValue.toJSON(JSONreps);
-
- /* this works */
- /*attributeJSONrep = {object:attributeValue, JSONrep:attributeJSONrep};
- JSONreps.push({object:attributeValue, JSONrep:attributeJSONrep});
- attributeJSONrep.JSONrep = attributeValue.toJSON(JSONreps);
- attributeJSONrep = attributeJSONrep.JSONrep;*/
}
/* fill out the JSON representation for this object */
if(attributeJSONrep === null) {
thisJSONrep[attributeList[i]] = attributeValue;
} else {
- //console.log("adding " + attributeList[i] + " json rep for " + thisJSONrep.name);
- //console.log(attributeJSONrep);
thisJSONrep[attributeList[i]] = attributeJSONrep;
}
}
View
@@ -739,6 +739,22 @@ describe("Model", function () {
expect(p.toJSON().friends[1].name).toBe("John");
expect(p.toJSON().friends[1].dog.name).toBe("Spot");
});
+
+ it("should not throw an error when called on a null value", function () {
+ var p, pJSON;
+
+ Person.hasA("nullValue");
+
+ p = new Person();
+ p.nullValue(null);
+
+ expect(function () {
+ pJSON = p.toJSON();
+ }).not.toThrow();
+
+ expect(pJSON).not.toBeUndefined();
+ expect(pJSON.nullValue).toBeNull();
+ });
});
});
View
@@ -246,25 +246,17 @@ window.jermaine.util.namespace("window.jermaine", function (ns) {
}
}
- if (attributeValue !== undefined && attributeValue.toJSON !== undefined && attributeJSONrep === null) {
+ if (attributeValue !== undefined && attributeValue !== null && attributeValue.toJSON !== undefined && attributeJSONrep === null) {
/* create a new entry for the attribute */
attributeJSONrep = (attributes[attributeList[i]] instanceof AttrList)?[]:{};
JSONreps.push({object:attributeValue, JSONrep:attributeJSONrep});
JSONreps[JSONreps.length-1].JSONrep = attributeValue.toJSON(JSONreps);
-
- /* this works */
- /*attributeJSONrep = {object:attributeValue, JSONrep:attributeJSONrep};
- JSONreps.push({object:attributeValue, JSONrep:attributeJSONrep});
- attributeJSONrep.JSONrep = attributeValue.toJSON(JSONreps);
- attributeJSONrep = attributeJSONrep.JSONrep;*/
}
/* fill out the JSON representation for this object */
if(attributeJSONrep === null) {
thisJSONrep[attributeList[i]] = attributeValue;
} else {
- //console.log("adding " + attributeList[i] + " json rep for " + thisJSONrep.name);
- //console.log(attributeJSONrep);
thisJSONrep[attributeList[i]] = attributeJSONrep;
}
}

0 comments on commit 99d8fd0

Please sign in to comment.