I’m a member of Adobe platform evangelism team located in Bucharest, Romania. Before I was software developer for a long time, mostly working on things related to J2EE world. Outside of work I enjoy traveling, going to the gym, reading and watching good movies Cornel is a DZone MVB and is not an employee of DZone and has posted 6 posts at DZone. View Full User Profile

AMF - Problems When Serializing Between Java and ActionScript

07.30.2008
| 8935 views |
  • submit to reddit

Below are some tips and tricks when dealing with serialization between Java and ActionScript. I’ve spent some time and encountered some frustrations (especially when I was too tired) trying to understand why the value is not properly sent over the wire so I decided to document all of my mistakes. Over the time I will edit this post to add new insights

  • if something seems wrong turn on debugging in services-config.xml
  • a property must have a public getter and setter in order to be serialized. I know that is strange (why should I have a setter when it’s not needed?) but that’s it. I do not like it all because sometimes it breaks encapsulation
  • you should take care to map the ActionScript class with the corresponding Java class using the metadata. For example [RemoteClass(alias="com.foo.model.MyClass")]
  • verify that the ActionScript object is included in the SWF file. If your project does not have a reference to the AS file then it will not be included in the resulting SWF so the Java class will be serialized to a generic object
  • you cannot serialize maps that have integers as keys See this bug
  • when serializing Hibernate entities be sure that all of them are initialized or use some kind of Open Session in View pattern - or better build a value object to contain only the data you really need.
  • a NULL number in Java is converted to 0 in ActionScript
  • a Long number from Java cannot be properly converted to Number in ActionScript - you will lose precision, so you should send it packed in a different way

From http://cornelcreanga.com/

Published at DZone with permission of Cornel Creanga, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Jamie Bisotti replied on Wed, 2008/07/30 - 11:14am

Is it safe to assume you are using BlazeDS?  Might want to mention that specifically.

Grante Data Services, has the concept of an Externalizer which can be used to (de-)serialize objects without requiring a default constructor and/or public getters/setters

We ran into the problem you describe in bullet #4 too.  What a pain.

Can you elaborate on your last point about LongS losing precision?

Thanks,

   Jamie

Cornel Creanga replied on Wed, 2008/07/30 - 5:18pm

Yes, I'm using BlazeDS, I should have mention that. Also I have to mention that I'm an Adobe employee.

Thanks for the information regarding GDS - In future I intend to spend some time doing a comparison between BlazeDS/GDS/WebORB and to write an article about that. It's a good thing to be able to choose between several products.

Java Long represents a number on 64 bits. ActionScript Number uses 64 bits but only 52 are used to store the significand (IEEE-754). That means precision is lost for long numbers stored on more than 52 bits (the same thing happens if you convert a Long to a Double in Java - try to do that with Long.MAX_VALUE for example). Sometime this conversion is not acceptable.

 

ramon wang replied on Sat, 2008/08/09 - 8:40am

Nice article, thanks.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.