GWT serialization of a subclass
Asked Answered
S

1

6

I have RPC service that returns an object of type GameEvent that extends from Event (abstract). When I get the object on the client side, all the properties inherited from Event (eventId, copyEventId, gameTimeGMT) are set to null whereas on the server side, these properties have values.

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: I use the gwt-platform framework (MVP implementation). Here is the call to the service client side. The result.getGE() returns the GameEvent object but with null properties.

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

The action handler:

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

The Result:

public class GetFormattedEventResult implements Result {

    private GameEvent e;

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

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

    public GameEvent getGE() {
        return e;
    }
}
Septennial answered 25/8, 2010 at 23:11 Comment(0)
C
0

I'll try to take a stab.

Verify that the Event class is in the GWT serialization whitelist (the .gwt.rpc file that is generated for each service interface). If it's not, you may have to trick GWT into adding it.

Calysta answered 25/8, 2010 at 23:32 Comment(4)
Updated the question. Also tried to trick GWT but it's not working.Septennial
The GameEvent had properties of a type that did not implement IsSerializable, that's why it was not in the serialization whitelist.Septennial
ahh, that makes sense. Sorry I couldn't be more help. GWTC should have issued a warning about that, though.Calysta
Was a solution found or not? And what was it? I am facing the same problem now and am curious of how you solved your problem.Krys

© 2022 - 2024 — McMap. All rights reserved.