AMF – Problems when serializing between Java and ActionScript

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
  • take care on timezone when serializing dates because it can have different values on client and server. The date object does not contains information related to it so if you need the timezone you should send it separately

2 Responses to “AMF – Problems when serializing between Java and ActionScript”

  1. Dirk Eismann Says:

    Concerning the coversion of NULL numbers from Java to AS3 (and especially sending a NaN from AS3 to Java which won’t be null on the Java side but 0!): when using BlazeDS you can implement your own mapping strategies on a field level by using a custom BeanProxy. I’m currently writing an article that I’ll put on my blog today (or tomorrow)

    Dirk.

  2. cornel Says:

    Thanks for sharing that – I will add a link to it

Leave a Reply