BlazeDS 未正确映射 AS 对象

发布于 2024-10-26 20:24:08 字数 1263 浏览 4 评论 0原文

我有 2 个相同的 java 类(想象一下 getter 和 setter):

class ScheduledEvent {
   private String eventName;
   private List<eventValues> values;      
}

class StartEvent {
   private String eventName;
   private List<eventValues> values;      
}

在 Flex 方面,我有相应的对象:

[RemoteClass(alias="com.project.events.ScheduledEvent")]  
public class ScheduledEvent {
   public var eventName:String;
   public var values:ArrayCollection;
}

[RemoteClass(alias="com.project.events.StartEvent")]  
public class StartEvent{
   public var eventName:String;
   public var values:ArrayCollection;
}

现在有两个相同的类是有原因的。当“计划”某些事情时,我应该获取 ScheduleEvent 对象,当事件启动时,我应该获取 StartEvent 对象。根据我返回的对象,我会做不同的事情。

我的问题是,在后端,它会向我发送 ScheduleEvent 对象,但是一旦它到达 Flex 端(通过 BlazeDS),它就会变成 StartEvent....

起初,我认为这是因为这两个事件恰好具有相同的变量,所以我尝试通过添加虚拟变量(String foobar)来更改 ScheduledEvent,但这似乎没有什么区别。

有谁知道为什么会发生这种情况以及我该如何解决它?

谢谢。

编辑: 我应该提到我没有使用 java 方法调用...我正在使用 BlazeDS 消息系统。这就是为什么我没有使用“一个 java 方法调用一个响应者”的方法。因此,在 message.body 中,我应该收到 ScheduledEvent,但我一直收到 StartEvent。我想知道是否是因为这两个对象具有相同的属性,而 BlazeDS 不知道如何正确映射它们...我什至在 java 服务层中放置了一个断点,以确保发送适当的对象但当 BlazeDS 将其序列化和反序列化到 Flex 端时,它现在是一个 StartEvent。我想知道如何解决这个问题。谢谢。

I have 2 java classes that are the same (imagine the getters and setters):

class ScheduledEvent {
   private String eventName;
   private List<eventValues> values;      
}

class StartEvent {
   private String eventName;
   private List<eventValues> values;      
}

On the flex side, I have the corresponding objects:

[RemoteClass(alias="com.project.events.ScheduledEvent")]  
public class ScheduledEvent {
   public var eventName:String;
   public var values:ArrayCollection;
}

[RemoteClass(alias="com.project.events.StartEvent")]  
public class StartEvent{
   public var eventName:String;
   public var values:ArrayCollection;
}

Now there is a reason why there are two classes that are the same. When something is "scheduled", I should get the ScheduleEvent object and when an event is started, I should get the StartEvent object. And depending on the object I get back, I do different things.

My problem is that, on the backend, it will send me the ScheduleEvent object, but once it got to the flex side (via BlazeDS), it becomes a StartEvent....

At first, I thought it's because these two events have exactly the same variables, so I tried changing ScheduledEvent by adding a dummy variable (String foobar) but that didn't seem to make a difference.

Does anyone have any idea why this is happening and how I can go about fixing it?

Thanks.

EDIT:
I should mentioned that I'm not using java method call... I'm using BlazeDS messaging system. That's why I am not using "one java method call to one responder" approach. So, in the message.body, I should be getting ScheduledEvent but I keep receiving StartEvent. I'm wondering if it's because the two objects have the same property and BlazeDS doesn't know how to map them correctly... I even put a break point in the java service layer, to make sure that the appropriate object is being sent back and it is... But by the time BlazeDS serializes and deserializes it to the flex side, it is now a StartEvent. And I'm wondering how this can be fixed. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冧九 2024-11-02 20:24:09

通常的方法是使用一个带有类型属性的类,然后根据类型决定要做什么。

就 BlazeDS 的行为而言:这里没有足够的信息可以确定,但如果您有一个 java 方法调用,则返回的对象将始终是相同的类型。如果您有一个名为 getEvent() 的方法,它返回一个 sheduledEvent 对象,那么它总是会返回一个 ScheduledEvent 对象。如果您有两个方法调用 - getScheduledEvent() 和 getStartEvent() - 那么您可以在 Flex 端有不同的响应者并在那里启动不同的逻辑。

The usual way to do this is to have a single class with a type property, then make your decision about what to do based on the type.

As far as the BlazeDS behaviour goes: there's not really enough information here to know for sure, but if you have a single java method call, the returned object will always be the same type. If you've got a method called getEvent() that returns a sheduledEvent object, then it's always going to return a scheduledEvent object. If you have two method calls - getScheduledEvent() and getStartEvent() - then you could have different responders on the flex side and start your differing logic there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文