PDA

View Full Version : serialization exception using java enum



reecegwt
1 Nov 2009, 7:30 PM
Hi,

I have a model class extending BaseModelData.
This class uses java enum ResultType.

public class RefineSearchModel extends BaseModelData
{

private static final long serialVersionUID = 7845586154338722931L;

public static final String RESULTTYPE = "resultType";
public static final String NAME = "name";

public RefineSearchModel()
{
super();
}


public RefineSearchModel(String name, ResultType type)
{
set(NAME,name);
set(RESULTTYPE,type);

}

/**
* set the result type
*
public void setResultType(ResultType resultType){

set(RESULTTYPE,resultType);
}



public ResultType getResultType()
{
return get(RESULTTYPE);
}

===============================================

enum is :

public enum ResultType
{
SECTION("section"),
CATEGORY("category"),
BRAND("brand"),
STYLE("style");

private final String description;

private ResultType(String description)
{
this.description = description;
}

@Override
public String toString()
{
return description;
}
}

=================================================

in view on client side

RpcProxy<List<RefineSearchModel>> proxy = new RpcProxy<List<RefineSearchModel>>() {

@Override
protected void load(Object loadConfig,
AsyncCallback<List<RefineSearchModel>> callback)
{
productService.getRefineSearchSections(keywords,
sectionCode,
callback);
}
};


implementation of method :

public List<RefineSearchModel> getRefineSearchSections(String keywords,
String sectionCode)
{
List<RefineSearchModel> sections = new ArrayList<RefineSearchModel>();

RefineSearchModel section1 = new RefineSearchModel("TOOLS",ResultType.SECTION);
sections.add(section1);
return sections;
}




I get the serializationException with RPC

Caused by: com.google.gwt.user.client.rpc.SerializationException: Type 'au.com.reece.cc.gwt.client.model.ResultType' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.
at com.google.gwt.user.server.rpc.impl.StandardSerializationPolicy.validateSerialize(StandardSerializationPolicy.java:83)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:591)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:129)
at com.extjs.gxt.ui.client.data.RpcMap_CustomFieldSerializer.serialize(RpcMap_CustomFieldSerializer.java:37)

Any help?

Thanks
Reece

sven
2 Nov 2009, 3:52 PM
Add a field to your RefineSearchModel of the type ResultType. Than GWT knows that you want to send it over RPC.

reecegwt
3 Nov 2009, 3:24 PM
Thanks sven.It works!

jimmy6
8 Jan 2011, 12:17 AM
I am facing almost same issue but what do you mean by add a field??? but it said that error is in servlet class rather than parameter object.

RpcProxy<PagingLoadResult<SentSmsTableModel>> proxy = new RpcProxy<PagingLoadResult<SentSmsTableModel>>() {
@Override
public void load(Object loadConfig, AsyncCallback<PagingLoadResult<SentSmsTableModel>> callback) {
// callback.
sendSmsRpcAsync.findSentSmsByCurrentUser( callback);

}
};

com.google.gwt.user.client.rpc.SerializationException: Type 'com.abc.controller.gwtrpc.SendSmsRpcImpl$1' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = com.abc.controller.gwtrpc.SendSmsRpcImpl$1@192dc2b
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:614)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)

sven
8 Jan 2011, 3:03 AM
How does your SentSmsTableModel model look like? how does your SendSmsRpcImpl class look like?