RPC Serialization of abstract classes

251 views
Skip to first unread message

mirceade

unread,
May 13, 2009, 3:52:15 PM5/13/09
to Google Web Toolkit
Hi,
I've got a problem for which I've filled a bug but I thought I should
have started with the forum first:

I've got an abstract class with an abstract field. I send an object
whose class is derived from this abstract class with the abstract
property set to another object. When sending the parent object through
RPC it's field becomes null with no serialization exception:

public abstract class AbProperty {
}

public abstract class AbClass {
AbProperty abProperty;
}

public class RealProperty extends AbProperty {
}

public class RealClass extends AbClass {
}


AbClass rc= new RealClass();
rc.setAbProperty(new RealProperty());

---> rpc
on the client an AbClass result is expected but debugging reveals that
rc.abProperty is null!!!

Help is very, very, very much appreciated.
Thanks.

Jim

unread,
May 13, 2009, 4:59:50 PM5/13/09
to Google Web Toolkit
The code you posted is not right because any class doesn't implements
java.io.Serializable.

You may try to implement java.io.Serializable in any class including
abstract class.

Jim
http://www.gwtorm.com
http://code.google.com/p/dreamsource-orm/

mirceade

unread,
May 14, 2009, 9:29:46 AM5/14/09
to Google Web Toolkit
Hi Jim,
Forgot to add:

All classes are defined in the client package and implement
Serializable (yes I know that only the base classes actually have to,
but for the sake of it they all do).
That was just an example to understand the inheritance.



On May 13, 11:59 pm, Jim <jim.p...@gmail.com> wrote:
> The code you posted is not right because any class doesn't implements
> java.io.Serializable.
>
> You may try to implement java.io.Serializable in any class including
> abstract class.
>
> Jimhttp://www.gwtorm.comhttp://code.google.com/p/dreamsource-orm/

mirceade

unread,
May 14, 2009, 10:23:42 AM5/14/09
to Google Web Toolkit
Am I doing something wrong? Is this supposed not to happen by design
and I'm forgetting some configuration?

Paul Robinson

unread,
May 14, 2009, 10:43:25 AM5/14/09
to Google-We...@googlegroups.com
Without actual code, it's going to be hard to help. Are you defining
your fields to be final?

mirceade

unread,
May 14, 2009, 11:09:52 AM5/14/09
to Google Web Toolkit
Well,
here it is:


/*
* View.java
*/

package com.client.infrastructure.statemachine;

import com.google.gwt.user.client.ui.Panel;

import java.io.Serializable;
import java.util.HashMap;

public abstract class View implements Serializable {
/**
*
*/
private static final long serialVersionUID = 5321684062654183464L;
public abstract void doView(Panel panel, HashMap model);
}




/*
* ViewState.java
*/

package com.client.infrastructure.statemachine;

import java.io.Serializable;

public abstract class ViewState extends State implements Serializable{

/**
*
*/
private static final long serialVersionUID = 1460737022142028448L;
private View view;

@Override
void enter() {
this.onEnter();
}

@Override
void process() {
this.view.doView(null, null);
}

void exit() {
this.onExit();
}

/**
* @return the view
*/
public View getView() {
return view;
}

/**
* @param view the view to set
*/
public void setView(View view) {
this.view = view;
}

}






/*
* RealState.java
*/

package com.client.flows.core.base.states;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;

import com.client.infrastructure.gui.Composition;
import com.client.infrastructure.gui.Menu;
import com.client.infrastructure.gui.MenuButton;
import com.client.infrastructure.gui.Screen;
import com.client.infrastructure.statemachine.Event;
import com.client.infrastructure.statemachine.ViewState;

public class RealState extends ViewState implements Serializable {

/**
*
*/
private static final long serialVersionUID = 844593773394013632L;

@Override
public void onEnter() {
System.out.println("hello");
}
}



/*
* SimpleView.java
*/
package com.client.flows.core.views;

import java.io.Serializable;
import java.util.HashMap;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.client.infrastructure.gui.Composition;
import com.client.infrastructure.gui.MenuButton;
import com.client.infrastructure.gui.MenuButtonClickHandler;
import com.client.infrastructure.statemachine.View;

public class SimpleView extends View implements Serializable {

/**
*
*/
private static final long serialVersionUID = 3027649895615644495L;

public void doView(Panel panel, HashMap model) {
panel.clear();
}

}






/*
* FlowDefinitionsService.java
*
*/

package com.client;
import com.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import com.client.infrastructure.statemachine.FlowDefinition;
import com.client.infrastructure.statemachine.State;

import java.util.List;

@RemoteServiceRelativePath("flowdefs")
public interface FlowDefinitionsService extends RemoteService{
public State retrieveViewState();
}

/*
* FlowDefinitionsServiceAsync.java
*
*/

package com.client;
import java.util.List;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.client.infrastructure.statemachine.FlowDefinition;
import com.client.infrastructure.statemachine.State;


public interface FlowDefinitionsServiceAsync {
public abstract void retrieveViewState(AsyncCallback<State>
asyncCallback);
}


/*
* FlowDefinitionsServiceImpl.java
*
*/

package com.server;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.client.FlowDefinitionsService;
import com.client.flows.core.base.states.RealState;
import com.client.flows.core.views.SimpleView;
import com.client.infrastructure.statemachine.FlowDefinition;
import com.client.infrastructure.statemachine.State;
import
com.server.infrastructure.processor.FlowDefinitionProcessorMock;

@SuppressWarnings("serial")
public class MappedFlowDefinitionsServiceImpl extends
RemoteServiceServlet implements FlowDefinitionsService {

public State retrieveViewState() {
RealState state = new RealState();
state.setView(new SimpleView()); <--------------- this is debugged
as null on the client
return state;
}
}



on the client - startup code:

private final FlowDefinitionsServiceAsync flowDefinitionsService =
GWT.create(FlowDefinitionsService.class);
public class MainEntryPoint implements EntryPoint {

/** Creates a new instance of MainEntryPoint */
public MainEntryPoint() {
}

private static final AbsolutePanel loadingArea = new AbsolutePanel
();

/**
* The entry point method, called automatically by loading a
module
* that declares an implementing class as an entry-point
*/
public void onModuleLoad() {
flowDefinitionsService.retrieveViewState(new AsyncCallback<State>()
{

public void onFailure(Throwable caught) {

}

public void onSuccess(State result) {
System.out.println(result.toString()); !!!!! Breakpoint here !!!!!
<----------------------------------
}

});
}
}

Paul Robinson

unread,
May 14, 2009, 11:35:20 AM5/14/09
to Google-We...@googlegroups.com
I don't see anything wrong.

mirceade

unread,
May 14, 2009, 2:27:28 PM5/14/09
to Google Web Toolkit
I don't either, so it must be a serialization issue with gwt RPC. It
would be very helpful if somebody else would try to reproduce this bug
too.

mirceade

unread,
May 19, 2009, 4:22:28 AM5/19/09
to Google Web Toolkit
I don't want to become annoying, but has anyone noticed this while
using
GWT-RPC? Can it be reproduced on another configuration than mine?

mirceade

unread,
May 23, 2009, 1:45:07 PM5/23/09
to Google Web Toolkit
I think this is a duplicate of Issue 2557 that was fixed in 1.5 RC 2
but resurfaced in 1.6.4.

mirceade

unread,
Jun 1, 2009, 3:32:16 PM6/1/09
to Google Web Toolkit
Come on guys, hasn't anybody else used more than plain strings and
ints with GWT RPC? Is this really a bug (not serializing correctly up
on the inheritance chain) or am I doing it all wrong? Help!

On 14 Mai, 18:35, Paul Robinson <ukcue...@gmail.com> wrote:

Paul Robinson

unread,
Jun 1, 2009, 7:04:21 PM6/1/09
to Google-We...@googlegroups.com
I (and presumably many others) am serializing things from an inheritance
hierarchy without any problems.

I can suggest two things for you:
(1) reduce your code to the simplest working code that will show the
problem, and then append that code to the issue you created. The source
you posted to this thread didn't include all your code (eg State wasn't
there)
(2) Have you tried stepping through the GWT RPC code in a debugger to
see if the data gets written out and it if then gets read in? This
should tell you where the problem lies.

Paul

mirceade

unread,
Jun 2, 2009, 5:38:17 AM6/2/09
to Google Web Toolkit
Ok, that was what I wanted to know. I'll proceed with doing what you
suggested. Thanks.

mirceade

unread,
Jun 2, 2009, 7:14:40 AM6/2/09
to Google Web Toolkit
Well, I have finally found the problem:
Drums roll:
The GWT Timer class is not serializable (my super class had a Timer
field buried down in there)! The compiler doesn't complain at all and
when the time to serialize comes it just doesn't serialize the whole
class without throwing any exception. Thanks Paul for your support and
I'm sorry for wasting your time with this.
Reply all
Reply to author
Forward
0 new messages