From eedaeb8d40c0348b6c3c34e87e14eb93f0bb2a64 Mon Sep 17 00:00:00 2001 From: Cowtowncoder Date: Mon, 16 Feb 2015 14:09:05 -0800 Subject: [PATCH] Fixed #707 for 2.3.6 --- release-notes/VERSION | 15 ++++++++++----- .../jackson/databind/node/FloatNode.java | 4 +++- .../jackson/databind/node/TestNumberNodes.java | 16 ++++++++++++---- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/release-notes/VERSION b/release-notes/VERSION index f0e4e4fb84..9362a5e036 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -1,15 +1,20 @@ Project: jackson-databind -Version: 2.3.5 (13-Jan-2014) +Version: 2.3.6 (not yet released) -#496: Wrong result for TextNode("false").asBoolean(true) - (reported by Ivar R, ivarru@github) -#543: Problems resolving self-referential generic types. -#656: defaultImpl configuration is ignored for WRAPPER_OBJECT +#707: Error in getting string representation of an ObjectNode with a float number value + (reported by @navidqar) ------------------------------------------------------------------------ === History: === ------------------------------------------------------------------------ +2.3.5 (13-Jan-2014) + +#496: Wrong result for TextNode("false").asBoolean(true) + (reported by Ivar R, ivarru@github) +#543: Problems resolving self-referential generic types. +#656: defaultImpl configuration is ignored for WRAPPER_OBJECT + 2.3.4 (17-Jul-2014) #459: BeanDeserializerBuilder copy constructor not copying `_injectables` diff --git a/src/main/java/com/fasterxml/jackson/databind/node/FloatNode.java b/src/main/java/com/fasterxml/jackson/databind/node/FloatNode.java index bb6ee406a0..5259cdc9dd 100644 --- a/src/main/java/com/fasterxml/jackson/databind/node/FloatNode.java +++ b/src/main/java/com/fasterxml/jackson/databind/node/FloatNode.java @@ -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 diff --git a/src/test/java/com/fasterxml/jackson/databind/node/TestNumberNodes.java b/src/test/java/com/fasterxml/jackson/databind/node/TestNumberNodes.java index ca199d4a36..7879a2d562 100644 --- a/src/test/java/com/fasterxml/jackson/databind/node/TestNumberNodes.java +++ b/src/test/java/com/fasterxml/jackson/databind/node/TestNumberNodes.java @@ -126,17 +126,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);