Why are some Class properties hidden from dojo.toJson?

I have a class I've created using dojo.declare.  This class has a number of properties with default values.  I also have a method in the class that takes the object and puts it into a json string.  

But a funny thing is happening.  When I set a breakpoint just before the call to dojo.toJson all of the properties including those values set in the declare are correctly displayed in the debugger, but only those values that are not defaults are included in the json string.

For example,  if I have a class with a property of P1 and P2 and P2 has a default value (defined in the class--declare), and P1 is set manually only P1 is included in the json string returned from dojo.toJson().  See below:


var m = new myclass();
m.P1 = "Test";
m.createjson();

dojo.declare("myclass", null, {
P1 : "value1",
P2 : "value2",
    constructor: function (args) {
        dojo.mixin(this, args);
        },
   createjson: function(args) {
    var cJson = dojo.toJson(this);   //cJson string does not include P2

});

Open in new window

marketwareAsked:
Who is Participating?
 
marketwareAuthor Commented:
I don't know if there is an answer out there for this question.  My workaround is to manually populate the properties instead of relying on the default values.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.