4.3. Diving into Serialization — AS3 to Java and Back

Flex talks AS3 and BlazeDS talks Java, yet they have a fluent conversation. The secret behind this smooth flow of data between the two sides is the presence of the serialization and deserialization logic elements within BlazeDS. This logic element is the one that appropriately converts data types in one language to the types in the other. To understand how this element works and how you could help it do its job well, it is worthwhile to understand how the data types on the two sides map to each other.

The simplest case of mapping arises with the simple and primitive types, for example String, Boolean, and integer. An integer in AS3 can be int or uint implying signed and unsigned integers respectively. These simple data types convert over to exact corresponding types in Java, as follows:

  • String (AS3)java.lang.String (Java)

  • Boolean (AS3)java.lang.Boolean (Java)

  • int/uint (AS3)java.lang.Integer (Java)

However, BlazeDS is smart enough to support related types as well. For example, passing in an AS3 int type to a Java method that takes java.lang.Double, java.lang.Long, primitive double, or primitive int argument will not fail, but the value will be automatically converted over to the respective data type. Similarly, an AS3 Boolean type could be forced to map to a java.lang.String type, where it would pass in "true" and "false" string values to the method.

AS3 has a Number type that holds numerical values. The numerical values can ...

Get Professional BlazeDS: Creating Rich Internet Applications with Flex® and Java® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.