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.
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.
精彩评论