pascallouisperez / jsonmarshaller

JsonMarshaller is a Java 1.5 library that allows marshalling and unmarshalling of JSON objects to and from entities ("Java classes").
Apache License 2.0
1 stars 0 forks source link

scale and rounding for numerical types support on @Value #19

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It would be useful to be able to specify the scale and the rounding mode on 
numerical types. For instance

  @Value(scale = 2) double price;

or

  @Value(scale = 10, roundingMode = RoundingMode.FLOOR) BigDecimal percent;

By default, the number's scale would be preserved (current behavior) and 
the default rounding mode would be the banker's rounding 
(RoundingMode.HALF_EVEN).

When marshalled, the scale would be reduced to the specified scale. The 
scale would never be extended. Therefore if price = 5, it would marshall as

  "price":5

but if price is 5.064 it would marshall as

  "price":5.06

When unmarshalled, the value would be rounded if needed to the specified 
scale using the rounding mode specified.

Original issue reported on code.google.com by pascallo...@gmail.com on 18 Dec 2008 at 1:27

GoogleCodeExporter commented 9 years ago

Original comment by pascallo...@gmail.com on 18 Dec 2008 at 1:46

GoogleCodeExporter commented 9 years ago
Here is a patch with test cases that resolves this issue. I'm available to 
discuss the patch if needed. I made sure it works for double and BigDecimal 
numbers, as well as floats (which mostly behave like doubles).

Original comment by antoine....@gmail.com on 31 Jul 2010 at 7:05

Attachments: