GWT Serialisierung einer Unterklasse
-
01-10-2019 - |
Frage
Ich habe RPC-Dienst, ein Objekt vom Typ Gameevent zurück, dass
erstreckt sich von Ereignis (Auszug). Wenn ich das Objekt auf dem Client erhalten
Seite, alle Eigenschaften von Ereignis vererbt (eventId, copyEventId,
gameTimeGMT) gesetzt sind, während auf der Serverseite null
Diese
Eigenschaften haben Werte.
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() {
}
}
Update: Ich benutze die GWT-Plattform Rahmen (MVP-Implementierung). Hier ist der Aufruf an den Dienst Client-Seite. Die result.getGE()
gibt das Gameevent Objekt, sondern mit null
Eigenschaften.
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());
}
});
Der Aktionshandler:
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);
}
}
Das Ergebnis:
public class GetFormattedEventResult implements Result {
private GameEvent e;
@SuppressWarnings("unused")
private GetFormattedEventResult() {
}
public GetFormattedEventResult(GameEvent gameEvent) {
e = gameEvent;
}
public GameEvent getGE() {
return e;
}
}
Lösung
Ich werde versuchen, einen Stich zu nehmen.
Stellen Sie sicher, dass die Event-Klasse in der GWT-Serialisierung ist die weiße Liste (die .gwt.rpc
-Datei, die für jede Service-Schnittstelle erzeugt wird). Wenn es nicht ist, können Sie Trick haben GWT in ihm hinzufügen.