PDA

View Full Version : BigDecimal SerializationException



stemkev
11 Nov 2009, 7:09 AM
I am using a TextField that takes a custom object as its model. This model object contains a java.math.BigDecimal field.

BigDecimal is not supported by GWT but I am using a third-party extension library.
http://code.google.com/p/gwt-java-math/

However, when I submit a query to the back end I get the following stack trace. It looks as though a GXT class (RpcMap_CustomFieldSerializer) is trying to do the serialization of the BigDecimal field.

Any ideas on how to use BigDecimal in a ModelData subclass?





2009-11-11 14:45:33,503 [ERROR] An error has occured in Greenscope: java.math.BigDecimal
com.google.gwt.user.client.rpc.SerializationException:
java.math.BigDecimal
at com.mycompany.myapp.client.margincall.MarginCallService_TypeSerializer.raiseSerializationException(transient source for com.mycompany.myapp.client.margincall.MarginCallService_TypeSerializer:429)
at com.mycompany.myapp.client.margincall.MarginCallService_TypeSerializer.serialize(Native Method)
at com.google.gwt.user.client.rpc.impl.ClientSerializationStreamWriter.serialize(ClientSerializationStreamWriter.java:216)
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)
at com.mycompany.myapp.client.margincall.MarginCallService_TypeSerializer.serialize(Native Method)
at com.google.gwt.user.client.rpc.impl.ClientSerializationStreamWriter.serialize(ClientSerializationStreamWriter.java:216)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:129)
at com.extjs.gxt.ui.client.data.BaseModelData_FieldSerializer.serialize(transient source for com.extjs.gxt.ui.client.data.BaseModelData_FieldSerializer:16)
at com.mycompany.myapp.client.common.dto.BigDecimalPair_FieldSerializer.serialize(transient source for com.mycompany.myapp.client.common.dto.BigDecimalPair_FieldSerializer:15)
at com.mycompany.myapp.client.margincall.MarginCallService_TypeSerializer.serialize(Native Method)
at com.google.gwt.user.client.rpc.impl.ClientSerializationStreamWriter.serialize(ClientSerializationStreamWriter.java:216)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:129)
at com.mycompany.myapp.client.margincall.MarginCallFilterConfig_FieldSerializer.serialize(transient source for com.mycompany.myapp.client.margincall.MarginCallFilterConfig_FieldSerializer:41)
at com.mycompany.myapp.client.margincall.MarginCallService_TypeSerializer.serialize(Native Method)
at com.google.gwt.user.client.rpc.impl.ClientSerializationStreamWriter.serialize(ClientSerializationStreamWriter.java:216)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:129)
at com.mycompany.myapp.client.margincall.MarginCallService_Proxy.getMarginCalls(transient source for com.mycompany.myapp.client.margincall.MarginCallService_Proxy:46)
at com.mycompany.myapp.client.margincall.MarginCallPresenterImpl$2.load(MarginCallPresenterImpl.java:120)
at com.extjs.gxt.ui.client.data.RpcProxy.load(RpcProxy.java:21)
at com.extjs.gxt.ui.client.data.BaseLoader.loadData(BaseLoader.java:134)
at com.extjs.gxt.ui.client.data.BaseLoader.load(BaseLoader.java:98)
at com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar.doLoadRequest(PagingToolBar.java:678)
at com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar.refresh(PagingToolBar.java:611)
at com.mycompany.myapp.client.margincall.MarginCallGrid.refresh(MarginCallGrid.java:476)
at com.mycompany.myapp.client.margincall.MarginCallViewImpl.refreshGridContents(MarginCallViewImpl.java:151)
at com.mycompany.myapp.client.margincall.MarginCallPresenterImpl.onSubmitQuery(MarginCallPresenterImpl.java:293)
at com.mycompany.myapp.client.margincall.MarginCallPresenterImpl.access$1(MarginCallPresenterImpl.java:289)
at com.mycompany.myapp.client.margincall.MarginCallPresenterImpl$SubmitQueryButtonListener.componentSelected(MarginCallPresenterImpl.java:315)
at com.mycompany.myapp.client.margincall.MarginCallPresenterImpl$SubmitQueryButtonListener.componentSelected(MarginCallPresenterImpl.java:1)
at com.extjs.gxt.ui.client.event.SelectionListener.handleEvent(SelectionListener.java:20)
at com.extjs.gxt.ui.client.event.SelectionListener.handleEvent(SelectionListener.java:1)
at com.extjs.gxt.ui.client.event.BaseObservable.callListener(BaseObservable.java:176)
at com.extjs.gxt.ui.client.event.BaseObservable.fireEvent(BaseObservable.java:96)
at com.extjs.gxt.ui.client.widget.Component.fireEvent(Component.java:444)
at com.extjs.gxt.ui.client.widget.button.Button.onClick(Button.java:530)
at com.extjs.gxt.ui.client.widget.button.Button.onComponentEvent(Button.java:277)
at com.extjs.gxt.ui.client.widget.Component.onBrowserEvent(Component.java:760)
at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1320)
at com.google.gwt.user.client.DOM.dispatchEventAndCatch(DOM.java:1299)
at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1262)

sven
11 Nov 2009, 7:11 AM
It looks as though a GXT class (RpcMap_CustomFieldSerializer) is trying to do the serialization of the BigDecimal field.

No it is not doing that. You need to tell GWT that you want to serialize BigDecimal. Post your custom modeldata, and i tell you how you need to modify it.

stemkev
12 Nov 2009, 1:13 AM
Hi Sven,

Thanks for the reply. This is my model class.



package com.mycompany.myapp.client.common.dto;

import java.math.BigDecimal;

import com.extjs.gxt.ui.client.data.BaseModelData;

public class BigDecimalPair extends BaseModelData
{

public static final String MIN_VALUE = "minValue";

public static final String MAX_VALUE = "maxValue";


public void setMinValue(BigDecimal minValue)
{
set(MIN_VALUE, minValue);
}


public BigDecimal getMinValue()
{
return get(MIN_VALUE);
}


public void setMaxValue(BigDecimal maxValue)
{
set(MAX_VALUE, maxValue);
}


public BigDecimal getMaxValue()
{
return get(MAX_VALUE);
}


public String toString()
{

BigDecimal min = getMinValue();
BigDecimal max = getMaxValue();

if (min == null && max == null)
{
return null;
}

if (min == null)
{
return "< " + min;
}

if (max == null)
{
return "> " + max;
}

return min + " , " + max;

}

}

sven
12 Nov 2009, 3:43 AM
Just add
private BigDecimal tempField;

Do not use it, it has to be there so that the compiler knows about bigdecimal

stemkev
12 Nov 2009, 7:30 AM
Hi Sven,

That did the trick. Thanks very much for your help.

Jogilein
16 Apr 2010, 1:24 AM
Just for all those that read this post and think, fine I get an anonymous class:

http://blog.holyjeez.com/2008/09/16/gwt-serialization-error-missing-default-constructor/#comment-420

The new BaseModelData needs a Standard Constructor so you should do something like:



import java.math.BigDecimal;

import com.extjs.gxt.ui.client.data.BaseModelData;

/**
* A BigDecimal can be part of the map which is sent through a BaseModelData to
* the client. In general GWT does not support BigDecimal as serializable (till
* 2.0.3 is does not, maybe it will be added in 2.1.0).
*
* So a third party tool helps to support this types (see gwt-math). But the
* compiler still does not know that BaseModelData needs this type and so it
* will not add it (its just a map of objects). So this AdvancedBaseModelData
* adds a BigDecimal as attribute (which is not used), so that the compiler adds
* the support of this types to this class (using the 3rd party tool).
*
* Its also important that this class has a standard constructor, thats why you
* cannot use an anonymous class.
*
*
*/
public class AdvancedBaseModelData extends BaseModelData {
private static final long serialVersionUID = -1L;

// see
@SuppressWarnings("unused")
private BigDecimal tempBigDecimal;

public AdvancedBaseModelData() {
}
}


Just if you want to use the BaseModelData with BigDecimal (don't forget to use the mentioned 3rd library!)