disconcerning diffrences between serializejson and serialize

121 views
Skip to first unread message

mail...@gmail.com

unread,
Mar 30, 2015, 2:11:54 AM3/30/15
to lu...@googlegroups.com
Hi All

I came across a strage issue today, when storing data in a database I use serializejson when I retrieve it I use deserializejson
for some reason I am getting "invalid construct" when trying to deserializejson if I change this to use serialize instead of serializejson it works fine (with deserializejson I dod not try plain deserialize), if I check the data directly in the database the only diffrence is that the serializejson method uses double quotes and the serialize uses single quotes, so I tried a deserializeJson(replace(sVars.cVal, "\", "", "ALL")) and this works on original data, I found this most baffling

is this bug in deserializeJson?

Regards

GX

Jean Moniatte

unread,
Mar 30, 2015, 3:56:47 AM3/30/15
to lu...@googlegroups.com
If data is your original variable name, does deserializeJson(serializeJson(data)) work ?

The problem is probably introduced by the database storage step. Comparing serializeJson(data) with the string stored in the database will give you a better idea of what the issue could be.

Thanks,
Jean




--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/d40982ca-97c3-490d-bb26-aba72e7dc800%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mail...@gmail.com

unread,
Mar 30, 2015, 4:11:24 AM3/30/15
to lu...@googlegroups.com
jmoniatte,

Thanks for the input

I did the test you suggested, it has something to do with database because this works fine no errors:

<cfdump var="#sVars.sData.values#">
<cfdump var="#serialize(sVars.sData.values)#">
<cfdump var="#serializeJson(sVars.sData.values)#">
<cfdump var="#deserializeJson(serialize(sVars.sData.values))#">
<cfdump var="#deserializeJson(serializeJson(sVars.sData.values))#">


Im doing a normal insert into a postgresql database as such

                <cfquery name="sVars.qData" datasource="#request.MQ.oAuth.getOperatorDatasource()#">
                    insert into mq_gsdata (operator_id, data) values(
                        <cfqueryparam value="#arguments.nOperatorId#" cfsqltype="cf_sql_integer" />,
                        <cfqueryparam value="#serialize(sVars.sData.values)#" cfsqltype="cf_sql_longvarchar" />
                    );
                </cfquery>

and the select is strait forward too, the even stranger thing is that I do similar things im my app elsewhere and I have not run into this issue yet, maybe it has to do woth preservesinglequotes but im not using that elsewhere either

Regards

GX

Jean Moniatte

unread,
Mar 30, 2015, 4:15:14 AM3/30/15
to lu...@googlegroups.com
Maybe compare the JSON string stored in the database with the one you get back from the query in your code. Are they identical?

Thanks,
Jean


Jeroen Knoef

unread,
Mar 30, 2015, 6:21:30 AM3/30/15
to lu...@googlegroups.com
Hi GX,
Your cfqueryparam uses serialize, not serializeJSON. So that explains the single quotes.
The inverse of serialize() is evaluate() BTW, you may want to use that instead.
Regards,
J

mail...@gmail.com

unread,
Mar 30, 2015, 6:29:32 AM3/30/15
to lu...@googlegroups.com
Jean, when i compare them the only diffrence is single quotes as opposed to double quotes

Jean Moniatte

unread,
Mar 30, 2015, 6:35:00 AM3/30/15
to lu...@googlegroups.com
Like Jeroen said, use serializeJson instead of serialize in the cfquery block.

Thanks,
Jean


mail...@gmail.com

unread,
Mar 30, 2015, 6:56:50 AM3/30/15
to lu...@googlegroups.com
Thanks for the help all, I found the bug.. I was doing a jsStringFormat after reading the data from the database, that was the cause

Regards

GX
Reply all
Reply to author
Forward
0 new messages