How to get a strongly typed collection from BlazeDS?

I put Spring bean into my Flex application through BlazeDS. In my Java code, I return strongly typed lists. eg.

public List<Folder> getFolders(String path) { return dao.getFolders(path); } 

A Flex application receives data as ArrayCollection objects for AS3 objects, that is, not as ArrayCollection Folders that I want. I annotated my Flex class as follows:

 package myproject.vo { import com.adobe.cairngorm.vo.IValueObject; import mx.collections.ArrayCollection; [Bindable] [RemoteClass(alias="myproject.vo.Folder")] public class Folder extends PersistentObject implements IValueObject { public function Folder() {} } } 

I checked that I have getters / setters in my Java Folder class to match the properties in my Flex Folder class. Any ideas?

+6
flex blazeds
source share
4 answers

I finally resolved this issue by following a bit of googling. Here are the Flex removal rules I found:

  • Annotate a Flex value object to indicate the Java class to which it belongs. This is important if the package name is different. - eg. [Bindable] [RemoteClass (alias = "package.JavaClass")] public class FlexClass {}

  • Constructors MUST match Flex and Java value objects. I ended up sticking to public no-args constructors just to make it simple.

  • Getters and seters MUST match between Flex and Java value objects.

  • The final rule is a cracker β€” you MUST create instances of any classes that you need to execute to deserialize. At first glance, this should not be a problem, but I spent days trying to deserialize the results of the remote call getObjectsAtPath (), the PersistentObjects list, which contains the folder and document instances (both are subclasses of PersistentObject). Unless you explicitly create an instance of the class (in my case it is the Folder class), it is NOT included in the SWF file (unlike Java)! As a result, I create a dummy variable of type Folder to get around this.

Thank you all for your suggestions.

+11
source share

I look through all my server code, and I can’t remember whether it was necessary or not, but on the Java side I declare the returned values ​​as strongly typed lists:

 public List<Folder> getFolders(String path) { return dao.getFolders(path); } 
0
source share

Java generators are removed at compile time. JVM does not print collections at runtime. Anyway, I don't see your calling code, but it should put the return value from java in a variable that is declared like this:

 folders:ArrayCollection.<String> 
0
source share

You mentioned that your Folder class is complex; Does this mean that it contains links to other objects? In this case, you do not need to match all the other classes (and check the setters / getters, especially for the logical ones)?

0
source share

All Articles