自定义对象的 BlazeDS 和 ArrayList
我正在使用 BlazeDS 将 Flex 与 Java 连接起来。 我在将自定义对象的 ArrayLists 从 Flex 传递到 java 时遇到问题。
我有两个对象,一个称为类别,另一个称为部分。 类别有一个包含Section 对象的ArrayList。 我可以在 Flex 和 Java 之间来回发送类别对象的 ArrayList,问题是当我尝试访问已从 Flex 返回到 Java 的类别对象的部分 ArrayList 时,出现以下错误:
flex.messaging.MessageException: java.lang.ClassCastException : flex.messaging.io.amf.ASObject
由于某种原因,我我得到的是 ASObjects 的 ArrayList 而不是我的部分对象。 我尝试查找如何在 ActionScript 中显式键入数组,但我唯一能找到的是使用 Vector 对象,而 BlazeDS 不支持该对象。 是否可以在 Category 对象的 ArrayList 中传递 Section 对象的 ArrayList,还是我必须找到其他方法?
I'm using BlazeDS to connect Flex with Java. I'm having trouble passing ArrayLists of custom objects from Flex to java.
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
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对 AS3 最常见的抱怨之一是缺少类型化数组。 ArrayList 只包含对象,您必须自己转换结果。
下面是我将传递的 Java 和 AS3 类的示例。
在 Java 中:
顶级类:
Sections 类:
Category 类:
在 AS3 中:
您可以在此处了解有关 RemoteObjects 的更多信息: 数据访问
One of the most common complaints with AS3 is the lack of typed arrays. ArrayLists will only contain objects, you will have to cast the results yourself.
Here is an example of a Java and AS3 class that I would pass around.
In Java:
The top level class:
Sections class:
Category class:
In AS3:
You can learn more about remoteObjects here: Data Access
Flex 实际上发送回了一个 flex.messaging.io.ArrayCollection 对象。 下面是将其转换为我的 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:
真正的答案是,BlazeDS 很愚蠢,并且需要类引用来将活动脚本对象映射回 Java(即使它刚刚成功地将完全相同的对象从 Java 映射到 AS)。 今天我在完全相同的问题上浪费了相当多的时间。 我有很多类似的映射,它们都工作得很好,但今天我创建了一个新的映射,它开始给我类转换异常。
在这里找到答案:
您的案例解决方案中的链接将是:
可能有更好的选择,但我今天已经够了。
the real answer is, that BlazeDS is stupid, and requires class reference to map your active script object back into Java (even if it just successfully mapped exactly the same object from Java to AS). I wasted quite some time on exactly the same problem today. I had quite a few similar mappings and they all worked fine, but today I created a new one, and it started to give me class cast exception.
found an answer here: Link
in your case solution would be:
there might be better options but I had enough for today.