July 2007 Archives

Flex 2.0.1 Hotfix 3 - The WebService Fix

| No Comments | No TrackBacks

...and it couldn't have come at a better time for me.

I've been hard at work on a large Flex 2 application that utilizes Web Services to communicate with the back-end. I've run into a number of issues that had to be worked around, all of which appear to be fixed by Flex 2.0.1 Hotfix 3.

It looks like Hotfix 3's main focus has been the Web Service classes, adding more stability and fixing lingering issues. This should be a welcome update to anyone who's been banging their head against a wall using Web Services.

One of the issues in particular, using a secure wsdl switches useProxy to true which breaks applications, was quite a pain to deal with. This is where the Open Source Flex announcement really pays dividends. I was able to find the issue in the public facing bugbase and monitor progress. I was happy to see that the issue was already reported, that it already had a valid workaround, and that it was going to be fixed in an upcoming Hotfix 3 release. Kudos to Adobe for having transparency here.

As with any Hotfix release, if you're not experiencing any of the issues that were fixed then it is not recommend that you upgrade. As they say... if it ain't broke...

However, if you're using Web Services you might want to consider the Hotfix 3 upgrade at http://www.adobe.com/go/kb402381.

I've had a few people ping me recently about unexpected parse errors they've encountered while decoding JSON strings using the ActionScript 3 JSON library (part of as3corelib). The fix is easy, but not entirely obvious.

It turns out that in all of the cases where erroneous parse errors were reported, the JSON string looked something like this:

{ prop1: 12, prop2: "hello, world" }

Can you spot the problem?

According to the JSON spec, the above snippet is not actually valid JSON. The reason? It's because the object property identifiers are not string literals. It may be valid JavaScript/ActionScript for creating an object via a literal, but JSON objects contain pairs of string : value and strings are always enclosed in double quotes.

The ActionScript 3 JSON parser I made is a bit on the strict side, I guess. From what I can gather, a lot of JSON decoders will accept the above snippet as valid JSON. Even worse, a lot of JSON encoders will produce JSON in the above format. That is, when you create a JSON string, behind the scenes the JSON string might not actually be valid. Typically the libraries that produce snippets without quotes around object identifiers will also accept those as valid input, so it's usually not a problem.

So, if you're running into parse errors when trying to decode JSON strings in ActionScript 3... make sure the JSON string is actually valid. The first place to look is for quoted identifiers in objects.

If you're using Ruby on Rails and running into this problem, a simple configuration change on the server end will fix the problem:

>> ActiveSupport::JSON::unquote_hash_key_identifiers=false
=> false

Thanks to Richard Wallace for pointing out the Rails configuration change necessary to produce valid JSON for the ActionScript 3 JSON decoder.

Flex.org - The Directory for Flex

Archives