有我丟失的東西:SerializationException的字符串數組
在Serializable Types它明確地說什麼連載:
類型是序列化類型(包括其他 序列化數組)的數組。
但是我不能序列new String[]{"s"}
public void onModuleLoad()
{
HashMap<String, String[]> p = new HashMap<String, String[]>();
p.put("xxx", new String[]{"s"});
ArrayList params = new ArrayList();
params.add(p);
greetingService.greetServer(params, new AsyncCallback<String>()
{
@Override
public void onSuccess(String result)
{
// TODO Auto-generated method stub
}
@Override
public void onFailure(Throwable caught)
{
caught.printStackTrace();
}
});
}
在另一方面,我可以序列化此:
ArrayList list = new ArrayList();
list.add("s");
這裏是例外,我得到:
com.google.gwt.user.client.rpc.SerializationException
at com.google.gwt.user.client.rpc.impl.SerializerBase.getTypeHandler(SerializerBase.java:153)
at com.google.gwt.user.client.rpc.impl.SerializerBase.serialize(SerializerBase.java:125)
at com.google.gwt.user.client.rpc.impl.ClientSerializationStreamWriter.serialize(ClientSerializationStreamWriter.java:183)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
at com.google.gwt.user.client.rpc.core.java.util.Map_CustomFieldSerializerBase.serialize(Map_CustomFieldSerializerBase.java:53)
at com.google.gwt.user.client.rpc.core.java.util.HashMap_CustomFieldSerializer.serialize(HashMap_CustomFieldSerializer.java:39)
at com.google.gwt.user.client.rpc.core.java.util.HashMap_FieldSerializer.serial(HashMap_FieldSerializer.java:23)
at com.google.gwt.user.client.rpc.impl.SerializerBase.serialize(SerializerBase.java:126)
at com.google.gwt.user.client.rpc.impl.ClientSerializationStreamWriter.serialize(ClientSerializationStreamWriter.java:183)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
at com.google.gwt.user.client.rpc.core.java.util.Collection_CustomFieldSerializerBase.serialize(Collection_CustomFieldSerializerBase.java:44)
at com.google.gwt.user.client.rpc.core.java.util.ArrayList_CustomFieldSerializer.serialize(ArrayList_CustomFieldSerializer.java:39)
at com.google.gwt.user.client.rpc.core.java.util.ArrayList_FieldSerializer.serial(ArrayList_FieldSerializer.java:23)
at com.google.gwt.user.client.rpc.impl.SerializerBase.serialize(SerializerBase.java:126)
at com.google.gwt.user.client.rpc.impl.ClientSerializationStreamWriter.serialize(ClientSerializationStreamWriter.java:183)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
at com.example.client.GreetingService_Proxy.greetServer(GreetingService_Proxy.java:31)
at com.example.client.AnotherTest.onModuleLoad(AnotherTest.java:56)
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:200)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Thread.java:662)
這裏的服務:
@RemoteServiceRelativePath("greet")
public interface GreetingService extends RemoteService
{
String greetServer(ArrayList name) throws IllegalArgumentException;
}
你能包括例外嗎?我認爲發送一個HashMap是可以的(發送一個Map也可以,但是在GWT-RPC的情況下,他們甚至會推薦具體的類,只生成需要的序列化代碼) – helios
僅用於測試,你可以嘗試序列化'HashMap'(SomeContainer是一個包含數組的類)。或者,'HashMap >'。我知道這不是什麼文件說...但它可以給一些光,如果它的工作... –
helios
我發佈了異常。我會嘗試你的建議 – Spiff