FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix a bug that fails to serialize BigDecimal by komamitsu · Pull Request #540 · msgpack/msgpack-java · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ private void packBigDecimal(BigDecimal decimal)
if (failedToPackAsBI) {
double doubleValue = decimal.doubleValue();
//Check to make sure this BigDecimal can be represented as a double
if (!decimal.stripTrailingZeros().toEngineeringString().equals(BigDecimal.valueOf(doubleValue).toEngineeringString())) {
if (!decimal.stripTrailingZeros().toEngineeringString().equals(
BigDecimal.valueOf(doubleValue).stripTrailingZeros().toEngineeringString())) {
throw new IllegalArgumentException("MessagePack cannot serialize a BigDecimal that can't be represented as double. " + decimal);
}
messagePacker.packDouble(doubleValue);
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,12 @@ public void testBigDecimal()
double d0 = 1.23456789;
double d1 = 1.23450000000000000000006789;
String d2 = "12.30";
String d3 = "0.00001";
List<BigDecimal> bigDecimals = Arrays.asList(
BigDecimal.valueOf(d0),
BigDecimal.valueOf(d1),
new BigDecimal(d2),
new BigDecimal(d3),
BigDecimal.valueOf(Double.MIN_VALUE),
BigDecimal.valueOf(Double.MAX_VALUE),
BigDecimal.valueOf(Double.MIN_NORMAL)
Expand All @@ -320,6 +322,7 @@ public void testBigDecimal()
assertEquals(d0, unpacker.unpackDouble(), 0.000000000000001);
assertEquals(d1, unpacker.unpackDouble(), 0.000000000000001);
assertEquals(Double.valueOf(d2), unpacker.unpackDouble(), 0.000000000000001);
assertEquals(Double.valueOf(d3), unpacker.unpackDouble(), 0.000000000000001);
assertEquals(Double.MIN_VALUE, unpacker.unpackDouble(), 0.000000000000001);
assertEquals(Double.MAX_VALUE, unpacker.unpackDouble(), 0.000000000000001);
assertEquals(Double.MIN_NORMAL, unpacker.unpackDouble(), 0.000000000000001);
Expand Down

Back | FazBrowse Home | New Git URL