BAEL-2412

Add example of deserialization of a double whose precission is too high.
This commit is contained in:
Javier 2018-12-12 06:00:53 +01:00
parent bc1a22babc
commit 24bd4644ff
2 changed files with 19 additions and 2 deletions

View File

@ -0,0 +1,9 @@
package org.baeldung.gson.primitives.models;
public class DoubleExample {
public double value;
public String toString() {
return "{float: " + value + "}";
}
}

View File

@ -53,12 +53,20 @@ public class UnitTest {
}
@Test public void fromJsonPrecissionMismatch() {
String json = "{\"value\": 12.123456789123456}";
String json = "{\"value\": 12.123425589123456}";
Gson gson = new Gson();
FloatExample model = gson.fromJson(json, FloatExample.class);
assertEquals(12.123457f, model.value, 0.000001);
assertEquals(12.123426f, model.value, 0.000001);
}
@Test public void fromJsonPrecissionMismatchForDouble() {
String json = "{\"value\": 12.123425589123556}";
Gson gson = new Gson();
DoubleExample model = gson.fromJson(json, DoubleExample.class);
assertEquals(12.123425589124f, model.value, 0.000001);
}
@Test public void fromJsonOverflow() {
Gson gson = new Gson();
String json = "{\"value\": \"300\"}";