views:

880

answers:

4

What is your preferred approach to serializing BigDecimal in GWT?

Are there any clever workarounds, or do you simply use Double or String?

Of all of the GWT pains this is so far the biggest; I'd hate to create two models, one for server and one for GWT, and transform data from one to the other. On the other hand, while I don't care much about using String instead of, say, javax.xml.datatype.Duration, I have to use BigDecimal on the server because of the calculations, which means either two models and conversion, or tons of tiny conversions to BigDecimal for every calculation.

+3  A: 

To answer my own question, I just found gwt-math project which adds support for BigDecimal and solves my problem...

Also, here's the official request for BigDecimal support in GWT.

Domchi
+5  A: 

Here is a GWT java.math package implementation I've built:

http://code.google.com/p/gwt-java-math/

It is based on Apache Harmony's implementation but has been modified to run efficiently in Java Script using doubles rather than longs.

It includes an almost complete implementation of BigInteger, BigDecimal, MathContext, RoundingMode and Random.

Richard Zschech
A: 

Is gwt-math still the answer in a GWT 2.0 context?

wytten
I haven't tried it with GWT 2.0 yet, but I see there's a standing request to support GWT 2.0 so hopefully they'll add it: http://code.google.com/p/gwt-math/issues/detail?id=24
Domchi
A: 

Use gwt-java-math not gwt-math in the GWT 2.0 context.

GWT 2.1 will include gwt-java-math!

Richard Zschech
Richard, why is gwt-math not good for GWT 2.0? I've been using it without any problems in GWT 2.0.3.
Domchi