Skip to content

Commit

Permalink
Fixed #707
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 16, 2015
1 parent a69bd56 commit cc05493
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
5 changes: 5 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Project: jackson-databind
=== Releases ===
------------------------------------------------------------------------

2.4.6 (not yet released)

#707: Error in getting string representation of an ObjectNode with a float number value
(reported by @navidqar)

2.4.5 (13-Jan-2015)

#635: Reduce cachability of `Map` deserializers, to avoid problems with per-property config changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ public BigInteger bigIntegerValue() {

@Override
public String asText() {
return NumberOutput.toString(_value);
// As per [jackson-core#179]
// return NumberOutput.toString(_value);
return Float.toString(_value);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,25 @@ public void testDouble() throws Exception
// @since 2.2
public void testFloat()
{
FloatNode n = FloatNode.valueOf(0.25f);
FloatNode n = FloatNode.valueOf(0.45f);
assertStandardEquals(n);
assertTrue(0 != n.hashCode());
assertEquals(JsonToken.VALUE_NUMBER_FLOAT, n.asToken());
assertEquals(JsonParser.NumberType.FLOAT, n.numberType());
assertEquals(0, n.intValue());
assertEquals(0.25, n.doubleValue());
assertEquals(0.25f, n.floatValue());

// NOTE: conversion to double NOT as simple as with exact numbers like 0.25:
assertEquals(0.45f, n.floatValue());
assertEquals("0.45", n.asText());

// so; as double we'll get more complex number; however, should round-trip
// to something that gets printed the same way. But not exact value, alas, hence:
assertEquals("0.45", String.valueOf((float) n.doubleValue()));

assertNotNull(n.decimalValue());
// possibly surprisingly, however, this will produce same output:
assertEquals(BigInteger.ZERO, n.bigIntegerValue());
assertEquals("0.25", n.asText());
assertEquals("0.45", n.asText());

// 1.6:
assertNodeNumbers(FloatNode.valueOf(4.5f), 4, 4.5f);
Expand Down

0 comments on commit cc05493

Please sign in to comment.