issue in json ??

Questions, tips and tricks and techniques for scripting in Servoy

issue in json ??

Postby Hans Nieuwenhuis » Tue Feb 18, 2014 10:18 am

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
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: issue in json ??

Postby pbakker » Wed Feb 19, 2014 10:59 am

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
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: issue in json ??

Postby Hans Nieuwenhuis » Wed Feb 19, 2014 12:01 pm

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
Attachments
globals_nav_check.txt
(218.88 KiB) Downloaded 348 times
globals_nav.txt
(237.7 KiB) Downloaded 349 times
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: issue in json ??

Postby Hans Nieuwenhuis » Wed Feb 19, 2014 12:15 pm

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,
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: issue in json ??

Postby pbakker » Wed Feb 19, 2014 12:25 pm

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
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: issue in json ??

Postby Hans Nieuwenhuis » Wed Feb 19, 2014 1:32 pm

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
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: issue in json ??

Postby pbakker » Wed Feb 19, 2014 1:50 pm

What is the type of the value of the tab property?
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: issue in json ??

Postby Hans Nieuwenhuis » Wed Feb 19, 2014 2:55 pm

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()
                                ......
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: issue in json ??

Postby pbakker » Wed Feb 19, 2014 4:15 pm

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
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands


Return to Methods

Who is online

Users browsing this forum: No registered users and 10 guests