Page 1 of 1

issue in json ??

PostPosted: Tue Feb 18, 2014 10:18 am
by Hans Nieuwenhuis
Hi I noticed a difference in the json behaviour between 5.2 and 7.3.1

If i Use :
Code: Select all
globals.nav.programcheck = plugins.serialize.fromJSON(plugins.serialize.toJSON(globals.nav.program))


then in 5.2 globals.nav.programcheck and globals.nav.program are identical

If I do this in 7.3.1 they are not identical.

I also tried in 7.3.1

Code: Select all
globals.nav.programcheck = JSON.parse(JSON.stringify(globals.nav.program))


, same issue

Is this a bug ??

Regards,

Hans

Re: issue in json ??

PostPosted: Wed Feb 19, 2014 10:59 am
by pbakker
What is the actual difference?

And you should not use the serialize plugin if you just want to stringify/parse JavaScript objects, but use JSON instead

Paul

Re: issue in json ??

PostPosted: Wed Feb 19, 2014 12:01 pm
by Hans Nieuwenhuis
The first line of the original object is :
Code: Select all
{Bcal_CustProblems:{add_mode:1,base_form_name:"bcal_navCustProblemsPrim",delete_mode:1,description:"Customer Problems",detail_form:1,display_field_header:"header_cust_problems",divider_height:420,divider_locked:0,edit_in_list:1,filter:,list_form:1,method:,method_types:{hasBrowse:{...},hasEdit:{...}},new_in_list:1,path:null,record_locking:0,record_locking_rels:null,relation:null,relation_form:Undefined,report:,report_types:{hasBrowse:{...},hasEdit:{...}},search_form:Undefined,sort_label:"Nummer",sort_value:"cstprpl_nr desc",sort_value_org:"cstprpl_nr desc",sortcriteria:,startup_view:"T",tab:[selected=1.0],table_form:1,table_tab_form:false,update_mode:1,view:"table"}


The first line of the object globals.nav.programcheck = JSON.parse(JSON.stringify(globals.nav.program))

Code: Select all
{Bcal_CustProblems:{add_mode:1,base_form_name:"bcal_navCustProblemsPrim",delete_mode:1,description:"Customer Problems",detail_form:1,display_field_header:"header_cust_problems",divider_height:420,divider_locked:0,edit_in_list:1,filter:,list_form:1,method:,method_types:{hasBrowse:{...},hasEdit:{...}},new_in_list:1,path:null,record_locking:0,record_locking_rels:null,relation:null,report:,report_types:{hasBrowse:{...},hasEdit:{...}},sort_label:"Nummer",sort_value:"cstprpl_nr desc",sort_value_org:"cstprpl_nr desc",sortcriteria:,startup_view:"T",tab:,table_form:1,table_tab_form:false,update_mode:1,view:"table"}


As you can see one diff is that the first one containts : "relation_form:Undefined", the second one does not.

I have uploaded both objects compleet versions

Re: issue in json ??

PostPosted: Wed Feb 19, 2014 12:15 pm
by Hans Nieuwenhuis
It seems that if there are undefined values in the object the line :

Code: Select all
globals.nav.programcheck = JSON.parse(JSON.stringify(globals.nav.program))


will give a difference between globals.nav.programcheck and globals.nav.program

In servoy 5.2 this caused now issues.

I took care of those undefined values and after a quick test it seems to work now in 7.3.1.

I'll have to test some more ....

Regards,

Re: issue in json ??

PostPosted: Wed Feb 19, 2014 12:25 pm
by pbakker
Undefined/undefined is not a valid value in JSON, so that might be the cause of things.

If such entries remained while serializing back and forth objects previously, that would be a bug that is apparently now fixed.

Paul

Re: issue in json ??

PostPosted: Wed Feb 19, 2014 1:32 pm
by Hans Nieuwenhuis
Well, there is another issue if one of the values is an array :

original object first line :

Code: Select all
{Bcal_CustProblems:{add_mode:1,base_form_name:"bcal_navCustProblemsPrim",delete_mode:1,description:"Customer Problems",detail_form:1,display_field_header:"header_cust_problems",divider_height:420,divider_locked:0,edit_in_list:1,filter:,list_form:1,method:,method_types:{hasBrowse:{...},hasEdit:{...}},new_in_list:1,path:null,record_locking:0,record_locking_rels:null,relation:null,relation_form:null,report:,report_types:{hasBrowse:{...},hasEdit:{...}},search_form:null,sort_label:"Nummer",sort_value:"cstprpl_nr desc",sort_value_org:"cstprpl_nr desc",sortcriteria:,startup_view:"T",tab:[selected=1.0],table_form:1,table_tab_form:false,update_mode:1,view:"table"}


New objects first line after globals.nav.programcheck = JSON.parse(JSON.stringify(globals.nav.program))

Code: Select all
{Bcal_CustProblems:{add_mode:1,base_form_name:"bcal_navCustProblemsPrim",delete_mode:1,description:"Customer Problems",detail_form:1,display_field_header:"header_cust_problems",divider_height:420,divider_locked:0,edit_in_list:1,filter:,list_form:1,method:,method_types:{hasBrowse:{...},hasEdit:{...}},new_in_list:1,path:null,record_locking:0,record_locking_rels:null,relation:null,relation_form:null,report:,report_types:{hasBrowse:{...},hasEdit:{...}},search_form:null,sort_label:"Nummer",sort_value:"cstprpl_nr desc",sort_value_org:"cstprpl_nr desc",sortcriteria:,startup_view:"T",tab:,table_form:1,table_tab_form:false,update_mode:1,view:"table"}


As You can see in the first one the text "tab:[selected=1.0]" and the second line only has "tab:"

Regards,

Hans

Re: issue in json ??

PostPosted: Wed Feb 19, 2014 1:50 pm
by pbakker
What is the type of the value of the tab property?

Re: issue in json ??

PostPosted: Wed Feb 19, 2014 2:55 pm
by Hans Nieuwenhuis
It is part of the "old" servoy framework and defined as :
Code: Select all
globals.nav.program[_rec.program_name].tab = new Array()
         globals.nav.program[_rec.program_name].tab.selected = 1
               for (var j = 1; j <= _rec.program_to_programtabs.getSize(); j++) {
            globals.nav.program[_rec.program_name].tab[_tab_count] = new Object()
                                ......

Re: issue in json ??

PostPosted: Wed Feb 19, 2014 4:15 pm
by pbakker
Mmm, so that is an Array on which also a named property is set. I think it is logical that that is skipped in serialization, for sure when using JSON.

Again I think it is wrong that it worked in the past.

Paul