LiveCycle® Data Services Developer's Guide |
|||
| Developing Data Services Applications > Serializing Data > Serializing between ActionScript and Java > Explicitly mapping ActionScript and Java objects | |||
For Java objects that Flex does not handle implicitly, values found in public bean properties with get/set methods and public variables are sent to the client as properties on an Object. Private properties, constants, static properties, and read-only properties, and so on, are not serialized. For ActionScript objects, public properties defined with the get/set accessors and public variables are sent to the server.
LiveCycle Data Services uses the standard Java class, java.beans.Introspector, to get property descriptors for a Java bean class. It also uses reflection to gather public fields on a class. It uses bean properties in preference to fields. The Java and ActionScript property names should match. Native Flash Player code determines how ActionScript classes are introspected on the client.
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 for it to be linked into the SWF file and available at run time. 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 special Map object when it is sent to the server, but the object returned from the server to the clients is your original ActionScript type.
To restrict a specific property from being sent to the server from an ActionScript class, use the [Transient] metadata tag above the declaration of that property in the ActionScript class.
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 |
int If value < 0xF0000000 || value > 0x0FFFFFFF, the value is promoted to Number due to AMF encoding requirements. |
|
java.lang.Short, short |
int If i < 0xF0000000 || i > 0x0FFFFFFF, the value is promoted to Number. |
|
java.lang.Byte, byte[] |
int If i < 0xF0000000 || i > 0x0FFFFFFF, the value is promoted to Number. |
|
java.lang.Byte[] |
flash.utils.ByteArray |
|
java.lang.Double, double |
Number |
|
java.lang.Long, long |
Number |
|
java.lang.Float, float |
Number |
|
java.lang.Character, char |
String |
|
java.lang.Character[], char[] |
String |
|
java. math.BigInteger |
String |
|
java.math.BigDecimal |
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.util.Collection (for example, java.util.ArrayList) |
mx.collections.ArrayCollection |
|
java.lang.Object[] |
Array |
|
java.util.Map |
Object (untyped). For example, a java.util.Map[] is converted to an Array (of Objects). |
|
java.util.Dictionary |
Object (untyped) |
|
org.w3c.dom.Document |
XML object |
|
null |
null |
|
java.lang.Object (other than previously listed types) |
Typed Object Objects are serialized using Java bean introspection rules and also include public fields. Fields that are static, transient, or nonpublic, as well as bean properties that are nonpublic or static, are excluded. |
|
NOTE |
|
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. You can enable legacy XML support for the flash.xml.XMLDocument type on any channel that is defined in the services-config.xml file. For more information, see Configuring AMF serialization on a channel. |
You can support legacy AMF type serialization used in earlier versions of Flex and configure other serialization properties in channel definitions in the services-config.xml file.
The following table describes the properties you can set in the <serialization> element of a channel definition:
|
Property |
Description |
|---|---|
<ignore-property-errors>
true
</ignore-property-errors>
|
Default value is |
<log-property-errors>
false
</log-property-errors>
|
Default value is |
<legacy-collection>false</legacy-collection>
|
Default value is |
<legacy-map>false</legacy-map>
|
Default value is |
<legacy-xml>false</legacy-xml>
|
Default value is |
<legacy-throwable>false</legacy-throwable>
|
Default value is |
<type-marshaller>
className
</type-marshaller>
|
Specifies an implementation of flex.messaging.io.TypeMarshaller that translates an object into an instance of a desired class. Used when invoking a Java method or populating a Java instance and the type of the input object from deserialization (for example, an ActionScript anonymous Object is always deserialized as a java.util.HashMap) doesn't match the destination API (for example, java.util.SortedMap). Thus, the type can be marshalled into the desired type. |
<restore-references>
false
</restore-references>
|
Default value is |
<instantiate-types>
true
</instantiate-types>
|
Default value is |
LiveCycle Data Services ES 2.5
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/livecycle/es/sdkHelp/programmer/lcds/serialize_data_3.html