Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

serialize JSON with plus sign results in invalid JSON

I'm working with data via an IBM MQ call where a 0 is returned as +0.0 when this is serialized by ColdFusion 10 (10,0,11,285437) it results in invalid JSON and cannot be deserialized.

stPolicy = { "prem": "+0.0" };
serializedData = serializeJSON(stPolicy);
writeDump(isJSON(serializedData));
writeDump(deserializeJSON(serializedData));

This outputs NO for isJSON and an error when trying to deserialize JSON parsing failure at character 9:'+' in {"prem":+0.0}.

I'm able to work around this by replacing all +0 to 0, but I'm guessing this is a bug in ColdFusion. Has anyone else had this issue and implemented a better fix?

Bug report filed: Bug #3632972

like image 378
Matt Busche Avatar asked Sep 16 '13 17:09

Matt Busche


Video Answer


1 Answers

Adobe has the bug listed as fixed in their bug database, but it has not yet been released. Here's the fix I came up with. Simply replace the +0 with 0

private string function serializeJSONFixCF10(required string serializedData) {
  return replace(arguments.serializedData,'+0','0','all');
}
like image 198
Matt Busche Avatar answered Oct 20 '22 01:10

Matt Busche