6

我有 RPC 服务,它返回一个 GameEvent 类型的对象,该对象从 Event(抽象)扩展。当我在客户端获取对象时,从 Event (eventId、copyEventId、gameTimeGMT) 继承的所有属性都设置为,null而在服务器端,这些属性具有值。

public class GameEvent extends Event implements IsSerializable { 
    private String homeTeam; 
    private String awayTeam; 
    public GameEvent() { 
    } 
} 

// Annotation are from the twig-persist framework which should not 
// impact the serialization process. 
public abstract class Event implements IsSerializable { 
    @Key 
    protected String eventId; 
    @Index 
    protected String copyEventId; 
    protected Date gameTimeGMT; 
    protected Event() { 
    }
}

更新:我使用 gwt-platform 框架(MVP 实现)。这是对服务客户端的调用。result.getGE()返回 GameEvent 对象,但带有属性null

dispatcher.execute(
        new GetFormattedEventAction(
                id),
        new AsyncCallback<GetFormattedEventResult>() {

            @Override
            public void onFailure(Throwable caught) {
                caught.printStackTrace();
            }

            @Override
            public void onSuccess(
                    GetFormattedEventResult result) {
                FormattedGameEvent formattedGameEvent = new FormattedGameEvent(
                        result.getGE());
            }
        });

动作处理程序:

public class GetFormattedEventActionHandler implements
        ActionHandler<GetFormattedEventAction, GetFormattedEventResult> {

    @Override
    public GetFormattedEventResult execute(GetFormattedEventAction action,
            ExecutionContext context) throws ActionException {
        GameEvent gameEvent = null;
        QueryResultIterator<GameEvent> rs = datastore.find().type(
                GameEvent.class).addFilter("copyEventId", FilterOperator.EQUAL,
                action.getEventId()).returnResultsNow();
        if (rs.hasNext()) {
            gameEvent = rs.next();
        }
        return new GetFormattedEventResult(gameEvent);
    }
}

结果:

public class GetFormattedEventResult implements Result {

    private GameEvent e;

    @SuppressWarnings("unused")
    private GetFormattedEventResult() {
    }

    public GetFormattedEventResult(GameEvent gameEvent) {
        e = gameEvent;
    }

    public GameEvent getGE() {
        return e;
    }
}
4

1 回答 1

0

我会尝试刺伤。

验证 Event 类是否在 GWT 序列化白名单(.gwt.rpc为每个服务接口生成的文件)中。如果不是,您可能不得不欺骗 GWT来添加它。

于 2010-08-25T23:32:12.943 回答