2010-08-25 8 views
6

Ho un servizio RPC che restituisce un oggetto di tipo GameEvent che si estende dall'evento (abstract). Quando ottengo l'oggetto sul lato client , tutte le proprietà ereditate da Event (eventId, copyEventId, gameTimeGMT) sono impostate su null mentre sul lato server, queste proprietà hanno valori.Serializzazione GWT di una sottoclasse

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() { 
    } 
} 

Aggiornamento: utilizzo il framework gwt-platform (implementazione MVP). Ecco la chiamata al lato client del servizio. Lo result.getGE() restituisce l'oggetto GameEvent ma con le proprietà 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()); 
      } 
     }); 

Il gestore di azione:

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); 
    } 
} 

Il Risultato:

public class GetFormattedEventResult implements Result { 

    private GameEvent e; 

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

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

    public GameEvent getGE() { 
     return e; 
    } 
} 

risposta

0

cercherò di prendere una pugnalata.

Verificare che la classe Event sia nella whitelist di serializzazione GWT (il file .gwt.rpc generato per ogni interfaccia di servizio). In caso contrario, potrebbe essere necessario aggiungere trick GWT.

+0

Aggiornamento della domanda. Ho anche provato a ingannare GWT ma non funziona. – Sydney

+0

GameEvent aveva proprietà di un tipo che non implementava IsSerializable, ecco perché non era nella whitelist di serializzazione. – Sydney

+0

ahh, questo ha senso. Scusa, non potrei essere più d'aiuto. GWTC avrebbe dovuto emettere un avvertimento a riguardo, però. –

Problemi correlati