代码之家  ›  专栏  ›  技术社区  ›  Sydney

子类的GWT序列化

  •  6
  • Sydney  · 技术社区  · 15 年前

    我有一个RPC服务,它返回一个GameEvent类型的对象 扩展自事件(抽象)。当我拿到客户机上的东西时 从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() { 
        }
    }
    

    result.getGE() 返回GameEvent对象,但带有 无效的 属性。

    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;
        }
    }
    
    1 回复  |  直到 14 年前
        1
  •  0
  •   Community CDub    8 年前

    验证事件类是否在GWT序列化白名单( .gwt.rpc trick GWT 加入它。

    推荐文章