[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

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

0
marketware
Asked:
marketware
1 Solution
 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now