|
8 | 8 |
|
9 | 9 | import org.junit.Assert; |
10 | 10 |
|
| 11 | +import com.fasterxml.jackson.annotation.JsonTypeInfo; |
11 | 12 | import com.fasterxml.jackson.core.*; |
12 | 13 | import com.fasterxml.jackson.databind.*; |
13 | 14 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; |
@@ -69,7 +70,16 @@ static class Issue467TmpBean { |
69 | 70 |
|
70 | 71 | public Issue467TmpBean(int i) { x = i; } |
71 | 72 | } |
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 | + |
73 | 83 | /* |
74 | 84 | /********************************************************** |
75 | 85 | /* Unit tests |
@@ -172,10 +182,6 @@ public void testBase64Text() throws Exception |
172 | 182 | } |
173 | 183 | } |
174 | 184 |
|
175 | | - static class Issue709Bean { |
176 | | - public byte[] data; |
177 | | - } |
178 | | - |
179 | 185 | /** |
180 | 186 | * Simple test to verify that byte[] values can be handled properly when |
181 | 187 | * converting, as long as there is metadata (from POJO definitions). |
@@ -285,5 +291,12 @@ public void testConversionOfTrees() throws Exception |
285 | 291 | assertTrue("Expected Object, got "+tree.getNodeType(), tree.isBoolean()); |
286 | 292 | assertEquals(EXP, MAPPER.writeValueAsString(tree)); |
287 | 293 | } |
288 | | -} |
289 | 294 |
|
| 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