问题
I am trying to do this
Service Interface:
Boolean SaveObjectIntoDatabase(Object Entity);
ServiceAsync:
void SaveObjectIntoDatabase(Object Entity,AsyncCallback <Boolean> Callback);
then implementing it on the serviceimpl
with no success.
Is it that we cannot send a variable of type object via GWT RPC??
stack trace:
onModuleLoad() threw an exception
Exception while loading module com.BiddingSystem.client.BiddingSystem. See Development Mode for details.
java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396) at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:183) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:510) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352) at java.lang.Thread.run(Thread.java:662) Caused by: java.lang.RuntimeException: Deferred binding failed for 'com.BiddingSystem.client.Service' (did you forget to inherit a required module?) at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:53) at com.google.gwt.core.client.GWT.create(GWT.java:97) at com.BiddingSystem.client.BiddingSystem.onModuleLoad(BiddingSystem.java:63) ... 9 more Caused by: com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries) at com.google.gwt.dev.shell.ModuleSpace.rebind(ModuleSpace.java:595) at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:455) at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49) ... 11 more
回答1:
The class java.lang.Object is not serializable.
回答2:
GWT needs to know at compile time ALL of the classes that you will send via RPC. It generates appropriate stubs, etc. for each of them.
Unfortunately, being able to generically say that you're sending Object
isn't useful because it will generate a stub for Object
(actually it won't because it's not serializable, but imagine it does), but that stub would be useless for, for example, String
or Date
.
There are ways around this. One of the more common is to define an RPC API method that's never called that just lists all the types you want to send, ever:
public void allTypeIWantToMarshall(Date a, String b, Integer c, Trousers d /* etc */);
but clearly this is a horrible hack and a maintenance nightmare.
Better would be to redesign the API so it doesn't use Object
.
回答3:
make the object class itself implmenets serialisable interface
回答4:
Every class should be serializable in order to be send to server from client. Object is not serializable that is why you can't send it.
Every class should implement GWT isSerializable interface if you want to send it to the server. java.io.Serializable is not the same as GWT isSerializable
来源:https://stackoverflow.com/questions/4465692/gwt-sending-type-object-via-rpc