Ramanan Nathamuni
Ramanan Nathamuni

Reputation: 11

GWT with Serialization

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?

Upvotes: 0

Views: 109

Answers (2)

wrappid
wrappid

Reputation: 23

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

Upvotes: 1

Clement Amarnath
Clement Amarnath

Reputation: 5466

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

Upvotes: 1

Related Questions