Tôi có dịch vụ RPC trả về một đối tượng thuộc loại GameEvent rằng kéo dài từ Sự kiện (trừu tượng). Khi tôi nhận được đối tượng ở phía máy khách , tất cả các thuộc tính được kế thừa từ Sự kiện (eventId, copyEventId, gameTimeGMT) được đặt thành null
trong khi ở phía máy chủ, các thuộc tính này có giá trị.Nối tiếp GWT của một lớp con
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() {
}
}
Cập nhật: Tôi sử dụng khung gwt-nền tảng (triển khai MVP). Đây là cuộc gọi đến phía máy khách dịch vụ. result.getGE()
trả về đối tượng GameEvent nhưng với các thuộc tính 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());
}
});
Việc xử lý hành động:
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);
}
}
Kết quả:
public class GetFormattedEventResult implements Result {
private GameEvent e;
@SuppressWarnings("unused")
private GetFormattedEventResult() {
}
public GetFormattedEventResult(GameEvent gameEvent) {
e = gameEvent;
}
public GameEvent getGE() {
return e;
}
}
Đã cập nhật câu hỏi. Cũng cố gắng lừa GWT nhưng nó không hoạt động. – Sydney
GameEvent có các thuộc tính của một kiểu không triển khai IsSerializable, đó là lý do tại sao nó không nằm trong danh sách trắng tuần tự hóa. – Sydney
ahh, điều đó có ý nghĩa. Xin lỗi tôi không thể giúp đỡ nhiều hơn. Tuy nhiên, GWTC đã đưa ra cảnh báo về điều đó. –