BigDecimal serialization in GWT
Asked Answered
G

3

5

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.

General answered 29/10, 2009 at 18:30 Comment(1)
No such problem now. BigDecimal is now supported by GWT.Interact
M
10

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.

Massacre answered 11/11, 2009 at 11:16 Comment(1)
This project has been merged into GWT 2.1Massacre
I
12

As of GWT 2.1 support for java.math.BigDecimal is supported.
release-notes

Interact answered 16/4, 2012 at 19:24 Comment(0)
M
10

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.

Massacre answered 11/11, 2009 at 11:16 Comment(1)
This project has been merged into GWT 2.1Massacre
G
3

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.

General answered 29/10, 2009 at 19:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.