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;
}
}
Aggiornamento della domanda. Ho anche provato a ingannare GWT ma non funziona. – Sydney
GameEvent aveva proprietà di un tipo che non implementava IsSerializable, ecco perché non era nella whitelist di serializzazione. – Sydney
ahh, questo ha senso. Scusa, non potrei essere più d'aiuto. GWTC avrebbe dovuto emettere un avvertimento a riguardo, però. –