Skip to content

Commit d586506

Browse files
committed
also parse scientific notation as a double/decimal
`BigDecimal` and `Double`'s `.toString` uses scientific notation when the number has more than 6 decimal points. So, when you have a Jackson generated JSON payload, you may end up with something like ``` {"my-double": "3E-8"} ``` will fail with a NumberFormatException: ``` ! java.lang.NumberFormatException: For input string: "3E-8" ! at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ! at java.lang.Long.parseLong(Long.java:589) ! at java.lang.Long.parseLong(Long.java:631) ! at com.fasterxml.jackson.databind.util.TokenBuffer$Parser.getNumberValue(TokenBuffer.java:1392) ! at com.fasterxml.jackson.databind.util.TokenBuffer$Parser.getDoubleValue(TokenBuffer.java:1340) ! at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer.deserialize(UntypedObjectDeserializer.java:207) ! at com.fasterxml.jackson.databind.deser.std.MapDeserializer._readAndBindStringMap(MapDeserializer.java:430) ! at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:312) ``` It's a bit of a corner case; for me, I was converting a class with a non-standard descendant of `Number` (`scala.math.BigDecimal`) into a `Map<String, Object>` and it only broke once I got smaller numbers. Happy to write a unit test if that helps; I only didn't because I opened this from the github web UI.
1 parent 8e9da38 commit d586506

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/std/NumberDeserializers.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOEx
455455
return Double.NaN;
456456
}
457457
try {
458-
if (text.indexOf('.') >= 0) { // floating point
458+
if (text.indexOf('.') >= 0 || text.indexOf('E') >= 0) { // floating point
459459
if (ctxt.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) {
460460
return new BigDecimal(text);
461461
}

0 commit comments

Comments
 (0)