| Flex 2 Developer's Guide > Data Access and Interconnectivity > Configuring Data Services > Serializing data > Converting data from Java to ActionScript | |||
An object returned from a Java method is converted from Java to ActionScript. Flex also handles objects found within objects. Flex implicitly handles the Java data types in the following table:
|
Java type |
ActionScript type (AMF 3) |
|---|---|
|
java.lang.String |
String |
|
java.lang.Boolean, boolean |
Boolean |
|
java.lang.Integer |
int If i < 0xF0000000 || i > 0x0FFFFFFF, the value is promoted to Number. |
|
java.lang.Short |
int If i < 0xF0000000 || i > 0x0FFFFFFF, the value is promoted to Number. |
|
java.lang.Byte |
int If i < 0xF0000000 || i > 0x0FFFFFFF, the value is promoted to Number. |
|
java.lang.Byte[] |
flash.utils.ByteArray |
|
java.lang.Double |
Number |
|
java.lang.Long |
Number |
|
java.lang.Float |
Number |
|
java.lang.Character |
String |
|
java.lang.Character[] |
String |
|
java.util.Calendar |
Date Dates are sent in the Coordinated Universal Time (UTC) time zone. Clients and servers must adjust time accordingly for time zones. |
|
java.util.Date |
Date Dates are sent in the UTC time zone. Clients and servers must adjust time accordingly for time zones. |
|
java.lang.Object (other than previously listed types) |
Typed Object Objects are serialized using Java Bean introspection rules. Fields that are static, transient, or nonpublic are excluded. |
|
java.util.Collection |
mx.collection.ArrayCollection |
|
java.lang.Object[] |
Array |
|
java.util.Map |
Object (untyped) In Flex 1.5, java.util.Map was sent as an associative or ECMA Array. This is no longer a recommended practice. You can enable legacy Map support to associative Arrays, but Adobe recommends against doing this. For more information, see Providing legacy AMF serialization on a channel |
|
java.util.Dictionary |
Object (untyped) |
|
org.w3c.dom.Document |
XML object You can enable legacy XML support for the XMLDocument type on any channel defined in the services-config.xml file. For more information, see Providing legacy AMF serialization on a channel. |
|
null |
null |
|
Other classes that extend java.lang.Object |
Object (typed) Objects are serialized using Java Bean introspection rules. Fields that are static, transient, or nonpublic are excluded. |
For Java objects that Flex does not handle implicitly, values found in public getter/setter method pairs and public variables are passed to the client as properties on an Object. Private properties, constants, static properties, and read-only properties, and so on, are not serialized.
In the ActionScript class, you use the [RemoteClass(alias=" ")] metadata tag to create an ActionScript object that maps directly to the Java object. The ActionScript class to which data is converted must be used or referenced in the MXML file. A good way to do this is by casting the result object, as the following example shows:
var result:MyClass = MyClass(event.result);
The class itself should use strongly typed references so that its dependencies are also linked.
The following examples shows the source code for an ActionScript class that uses the [RemoteClass(alias=" ")] metadata tag:
package samples.contact {
[Bindable]
[RemoteClass(alias="samples.contact.Contact")]
public class Contact {
public var contactId:int;
public var firstName:String;
public var lastName:String;
public var address:String;
public var city:String;
public var state:String;
public var zip:String;
}
}
You can use the [RemoteClass] metadata tag without an alias if you do not map to a Java object on the server, but you do send back your object type from the server. Your ActionScript object is serialized to a Map object when it is sent to the server, but the object returned from the server to the clients is your original ActionScript type.
Flex 2
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flex/2/docs/00001104.html