|
3 | 3 | import java.math.BigDecimal; |
4 | 4 | import java.math.BigInteger; |
5 | 5 |
|
| 6 | +import com.fasterxml.jackson.databind.DeserializationFeature; |
| 7 | +import com.fasterxml.jackson.databind.ObjectReader; |
| 8 | +import com.fasterxml.jackson.databind.exc.MismatchedInputException; |
6 | 9 | import com.fasterxml.jackson.dataformat.xml.XmlMapper; |
7 | 10 | import com.fasterxml.jackson.dataformat.xml.XmlTestBase; |
8 | 11 | import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; |
@@ -67,6 +70,27 @@ public void testPrimitiveFPsWithEmpty() throws Exception |
67 | 70 | assertEquals(0f, p.f); |
68 | 71 | } |
69 | 72 |
|
| 73 | + public void testPrimitivesNoNulls() throws Exception |
| 74 | + { |
| 75 | + ObjectReader r = MAPPER |
| 76 | + .readerFor(NumbersPrimitive.class) |
| 77 | + .with(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES); |
| 78 | + _testPrimitivesNoNulls(r, _emptyWrapped("i")); |
| 79 | + _testPrimitivesNoNulls(r, _emptyWrapped("l")); |
| 80 | + _testPrimitivesNoNulls(r, _emptyWrapped("d")); |
| 81 | + _testPrimitivesNoNulls(r, _emptyWrapped("f")); |
| 82 | + } |
| 83 | + |
| 84 | + private void _testPrimitivesNoNulls(ObjectReader r, String doc) throws Exception |
| 85 | + { |
| 86 | + try { |
| 87 | + r.readValue(_emptyWrapped("i")); |
| 88 | + fail("Should not pass"); |
| 89 | + } catch (MismatchedInputException e) { |
| 90 | + verifyException(e, "Cannot coerce empty String"); |
| 91 | + } |
| 92 | + } |
| 93 | + |
70 | 94 | /* |
71 | 95 | /********************************************************************** |
72 | 96 | /* Test methods, Numbers / wrapper (or Object) |
|
0 commit comments