0
votes

This is my client side code to get the string "get-image-data" through RPC calls and getting byte[] from the server.

CommandMessage msg = new CommandMessage(itemId, "get-image-data");
cmain.ivClient.execute(msg, new AsyncCallback<ResponseMessage>() {

    @Override
    public void onFailure(Throwable caught) {

    }

    @Override
    public void onSuccess(ResponseMessage result) {
        if (result.result) {
            result.data is byte[].
        }
    }
});

From the server side I got the length of the data is 241336. But I could not get the value in onSuccess method. It is always goes to onFailure method.

And I got log on Apache:

com.google.gwt.user.client.rpc.SerializationException: Type '[B' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded.

How can I do serialisation in GWT?

2
What does ResponseMessage look like? The error says that byte[] cant be sent over the wire, and in your case, the server is saying that it isn't permitted for it to send that data. - Colin Alworth
What version of GWT are you using? My gut feeling tells me that byte[] should be serializable, but I will check. - Rade_303
byte[] is definitely serializable. developerlife.com/tutorials/?p=131 Check if maybe your browser cached old compiled JSs. Do a Ctrl-F5 to refresh the cache and it might work. - Rade_303
It is potentially serializable, but only if the rpc service has declared it to be something the server is permitted to send. - Colin Alworth

2 Answers

1
votes

1) Create a pojo which implements Serializable interface Let this pojo has all the data you want in the response of RPC service, in this case image-data

2) Pass this pojo in the response for your RPC service.

The below tutorial has enough information for creating RPC service http://www.gwtproject.org/doc/latest/tutorial/RPC.html

1
votes
  1. The objects you transfer to and from the server has to implement IsSerializable.

  2. All your custom Objects within the Object you are transferring also needs to implement IsSerializable.

  3. Your objects cannot have final fields and needs an no argument constructor.

  4. You need getters and setters.

A common serialize object in GWT:

public class MyClass implements IsSerializable {

       private String txt;
       private MyOtherClass myOtherClass; // Also implements IsSerializable

       public MyClass() {

       }

       public String getTxt() {
           return this.txt;
       }

       public void setTxt(String txt) {
           return this.txt = txt;
       }

       public String getMyOtherClass() {
           return this.myOtherClass;
       }

       public void setMyOtherClass(MyOtherClass myOtherClass) {
           return this.myOtherClass = myOtherClass;
       }
}