How do I get a strongly typed collection from BlazeDS?

后端 未结 4 1679
感动是毒
感动是毒 2021-02-09 18:45

I\'ve exposed a Spring bean to my Flex app via BlazeDS. In my Java code I return strongly typed lists. e.g.

public List getFolders(String path) {
          


        
相关标签:
4条回答
  • 2021-02-09 18:59

    I'm looking at all of my server-side code, and I can't remember if this was necessary or not, but on the Java side, I declare the return values as strongly-typed Lists:

    public List<Folder> getFolders(String path) { 
        return dao.getFolders(path); 
    }
    
    0 讨论(0)
  • 2021-02-09 19:02

    Java generics are stripped out at compile time. The JVM does not type collections at run time. Anyway, I don't see your calling code, but it should be putting the returned value from java into a variable that is declared kinda like this:

    folders:ArrayCollection.<String>
    
    0 讨论(0)
  • 2021-02-09 19:10

    You mentionned that your Folder class is complex ; does it mean that it contains references to other objects ? In this case don't you have to map every other classes (and check the setters / getters, especially for boolean) ?

    0 讨论(0)
  • 2021-02-09 19:12

    I finally resolved this issue following a bit of Googling. Here are the rules of Flex remoting that I found:

    1. Annotate the Flex value object to indicate the Java class that it relates to. This is essential if the package name differs. – e.g. [Bindable][RemoteClass(alias=”package.JavaClass”)] public class FlexClass {}

    2. The constructors MUST match in Flex and Java value objects. I ended up sticking to public no-args constructors just to keep it simple.

    3. Getters and setters MUST match between Flex and Java value objects.

    4. The last rule is a cracker – You MUST instantiate any classes that you need to deserialize to. On the face of it this shouldn’t be a problem however I spent days trying to deserialize the results of a remote getObjectsAtPath() call - a list of PersistentObjects which contained instances of Folder and Document (both are subclasses of PersistentObject). If you don’t explicitly instantiate the class (in my case the Folder class) it does NOT get included in the SWF file (unlike Java)! I eventually create a dummy variable of type Folder to get around this.

    Thanks to everyone for your suggestions.

    0 讨论(0)
提交回复
热议问题