I know that GWT doesn't support BigDecimal. Now we have a couple of
choices.
1. in legacy code, add
if(value instanceof BigDecimal) {
change value to a custom & IsSerializable class
}
2. Write a IsSerializable CBigDecimal class and replace all code
references of BigDecimal to CBigDecimal. Make sure CBigDecimal runs
both on gwt and legacy code.
3. Keep legacy code intact. Write a java.math.BigDecimal class at GWT
side.
I would love to go with 3 since it seems a purer solution. The major
problem here, is how to deserialize BigDecimal sent from server side.
It seems i have to touch some GWT internals. Are there any suggestions
on how to do this?
Thanks for the help!
BigDecimal is used in two distinct use cases:
1. Where you need really huge numbers, that easily outpace double's
limits. We're talking numbers with 300 digits or more.
2. Where you can't afford any rounding errors, e.g. in finance apps.
In case #1, you'll need to think about the propositions you mentioned.
#3 can work, by the way, but you'll indeed need to dive into GWT
internals. You should probably add a class to the enum package (see
GWT source, this is where the JSNI-ified versions of java.lang.*,
java.util.*, etcetera can be found).
In case #2 however, consider just using doubles. Yes, rounding errors,
but: In most apps the only actual 'math to keep' is done server-side.
Client side numbers are mostly displayed (doing financial MATH on
doubles is dangerous, but using a double to display a monetary amount
is absolutely no problem, you have perfect accuracy with 2 digits
after the decimal up to at least 100 billion dollars). Where there is
client-side math, I assume it's usually just in an effort to display
some aggregates, not to actually report back to the server and take as
canon.
Any form of accurate BigDecimal client-side would be very slow.