Skip to content

Commit

Permalink
Fix #1940
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 23, 2018
2 parents bc22f90 + c5bfb9a commit 9b1b35d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
5 changes: 5 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,8 @@ Deblock Thomas (deblockt@github)
[email protected]:
* Reported #1931: Two more `c3p0` gadgets to exploit default typing issue
(2.9.5)
Aniruddha Maru (maroux@github)
* Reported #1940: `Float` values with integer value beyond `int` lose precision if
bound to `long`
(2.9.5)
5 changes: 4 additions & 1 deletion release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Project: jackson-databind
(contributed by Deblock T)
#1931: Two more `c3p0` gadgets to exploit default typing issue
(reported by [email protected])
#1940: `Float` values with integer value beyond `int` lose precision if
bound to `long`
(reported by Aniruddha M)

2.9.4 (24-Jan-2018)

Expand Down Expand Up @@ -208,7 +211,7 @@ Project: jackson-databind
`MapperFeature.ALLOW_COERCION_OF_SCALARS`
(requested by magdel@github)

2.8.11.1 (not yet released)
2.8.11.1 (11-Feb-2018)

#1872: `NullPointerException` in `SubTypeValidator.validateSubType` when
validating Spring interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1637,8 +1637,7 @@ private final boolean _smallerThanLong(Number n) {
return (n instanceof Integer) || (n instanceof Short) || (n instanceof Byte);
}

/* 02-Jan-2017, tatu: Modified from method(s) in `ParserBase`
*/
// 02-Jan-2017, tatu: Modified from method(s) in `ParserBase`

protected int _convertNumberToInt(Number n) throws IOException
{
Expand Down Expand Up @@ -1689,7 +1688,7 @@ protected long _convertNumberToLong(Number n) throws IOException
if (d < MIN_LONG_D || d > MAX_LONG_D) {
reportOverflowLong();
}
return (int) d;
return (long) d;
} else if (n instanceof BigDecimal) {
BigDecimal big = (BigDecimal) n;
if (BD_MIN_LONG.compareTo(big) > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.junit.Assert;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.type.WritableTypeId;
import com.fasterxml.jackson.databind.*;
Expand Down Expand Up @@ -70,7 +71,16 @@ static class Issue467TmpBean {

public Issue467TmpBean(int i) { x = i; }
}


static class Issue709Bean {
public byte[] data;
}

@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="_class")
static class LongContainer1940 {
public Long longObj;
}

/*
/**********************************************************
/* Unit tests
Expand Down Expand Up @@ -173,10 +183,6 @@ public void testBase64Text() throws Exception
}
}

static class Issue709Bean {
public byte[] data;
}

/**
* Simple test to verify that byte[] values can be handled properly when
* converting, as long as there is metadata (from POJO definitions).
Expand Down Expand Up @@ -288,5 +294,12 @@ public void testConversionOfTrees() throws Exception
assertTrue("Expected Object, got "+tree.getNodeType(), tree.isBoolean());
assertEquals(EXP, MAPPER.writeValueAsString(tree));
}
}

// [databind#1940]: losing of precision due to coercion
public void testBufferedLongViaCoercion() throws Exception {
long EXP = 1519348261000L;
JsonNode tree = MAPPER.readTree("{\"longObj\": "+EXP+".0, \"_class\": \""+LongContainer1940.class.getName()+"\"}");
LongContainer1940 obj = MAPPER.treeToValue(tree, LongContainer1940.class);
assertEquals(Long.valueOf(EXP), obj.longObj);
}
}

0 comments on commit 9b1b35d

Please sign in to comment.