BlazeDS的和自定义对象的ArrayList [英] BlazeDS and ArrayList of custom objects
问题描述
我使用的BlazeDS与Java的连接Flex。我在传递自定义对象的ArrayList从Flex使用Java的麻烦。
I'm using BlazeDS to connect Flex with Java. I'm having trouble passing ArrayLists of custom objects from Flex to java.
我有两个对象,一个叫类别,其他科。一类具有部分对象的ArrayList。我可以发送一个ArrayList的范畴对象来回Flex和Java之间,问题是,当我尝试访问已从Flex的返回到Java一类对象的部分ArrayList中,我得到以下错误:
I have two objects, one is called Category, the other Section. A Category has an ArrayList of Section objects. I can send an ArrayList of Category objects back and forth between Flex and Java, the problem is when I try to access the sections ArrayList of a Category object that has been returned to Java from Flex, I get the following error:
flex.messaging.MessageException: java.lang.ClassCastException : flex.messaging.io.amf.ASObject
出于某种原因,我得到ASObjects的ArrayList,而不是我第对象。我试图寻找了如何明确ActionScript类型的数组,但我唯一能找到的是使用Vector对象,BlazeDS的不支持。是否有可能通过部分对象的ArrayList类对象的ArrayList中,还是我到处找另一种方式?
For some reason I'm getting an ArrayList of ASObjects rather than my Section objects. I tried looking up how to explicitly type arrays in actionscript, but the only thing I could find was using a Vector object, which BlazeDS does not support. Is it possible to pass an ArrayList of Section objects within an ArrayList of Category objects, or do I have to find another way around?
推荐答案
Flex的竟是发回flex.messaging.io.ArrayCollection对象。下面是code将其转换为我的Java类的ArrayList
Flex was actually sending back a flex.messaging.io.ArrayCollection object. Below is the code to convert this to an ArrayList of my java class:
public ArrayList<MyObject> convertArrayCollection(ArrayCollection array){
ArrayList<MyObject> myObjectArray = new ArrayList();
ASTranslator ast = new ASTranslator();
MyObject myObject;
ASObject aso;
for (int i=0;i< array.size(); i++){
myObject = new MyObject();
aso = new ASObject();
aso = (ASObject) array.get(i);
aso.setType("com.myPackage.MyObject");
myObject = (MyObject) ast.convert(aso, MyObject.class);
myObjectArray.add(myObject);
}
return myObjectArray;
}
这篇关于BlazeDS的和自定义对象的ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!