-
Notifications
You must be signed in to change notification settings - Fork 5
2. Serialization
Argonaut is really about inbound data (i.e., receiving and de-serializing JSON), but an outbound pipeline is also useful if you want to dispatch classes as JSON. The JSON class in AS3 does this (partially) by providing the JSON.stringify() method, but it has a rather serious limitation: there’s no way to suppress properties that aren’t needed for serialization.
For example, you might have this Class:
public class Example
{
public var name:String;
public var id:uint;
public const gravity:Number = 9.8;
public var textField:TextField;
}
When sending the JSON, you probably want to send name and id, but the constant gravity and the (very complex!) textField property probably shouldn’t go over the wire. To fix this, Argonaut provides a [DontSerialize] metatag. Edit the class to:
public class Example
{
public var name:String;
public var id:uint;
[DontSerialize]
public const gravity:Number = 9.8;
[DontSerialize]
public var textField:TextField;
}
If you run the instance through argonaut.stringify(), the resulting JSON will only include only that name and id fields. Note that use of the [DontSerialize] metatag requires -keep-as3-metadata+=“DontSerialize” to be marked in the compiler.
-static-link-runtime-shared-libraries=true
-target-player={playerVersion}
-library-path+="{flexSDK}/frameworks/locale/en_US"
-default-size=550,400
-use-network=false
-keep-as3-metadata+=“DontSerialize”
Finally, the Argonaut serializer automatically tags JSON objects with a “jsonclass” tag so that a recipient may also know the datatype of any complex objects.