Skip to content

Commit c5bfb9a

Browse files
committed
Add test for #1940
1 parent 9612972 commit c5bfb9a

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/test/java/com/fasterxml/jackson/databind/node/TestConversions.java

+19-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import org.junit.Assert;
1010

11+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
1112
import com.fasterxml.jackson.core.*;
1213
import com.fasterxml.jackson.databind.*;
1314
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@@ -69,7 +70,16 @@ static class Issue467TmpBean {
6970

7071
public Issue467TmpBean(int i) { x = i; }
7172
}
72-
73+
74+
static class Issue709Bean {
75+
public byte[] data;
76+
}
77+
78+
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="_class")
79+
static class LongContainer1940 {
80+
public Long longObj;
81+
}
82+
7383
/*
7484
/**********************************************************
7585
/* Unit tests
@@ -172,10 +182,6 @@ public void testBase64Text() throws Exception
172182
}
173183
}
174184

175-
static class Issue709Bean {
176-
public byte[] data;
177-
}
178-
179185
/**
180186
* Simple test to verify that byte[] values can be handled properly when
181187
* converting, as long as there is metadata (from POJO definitions).
@@ -285,5 +291,12 @@ public void testConversionOfTrees() throws Exception
285291
assertTrue("Expected Object, got "+tree.getNodeType(), tree.isBoolean());
286292
assertEquals(EXP, MAPPER.writeValueAsString(tree));
287293
}
288-
}
289294

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

0 commit comments

Comments
 (0)