@@ -57,70 +57,79 @@ public MyBeanValue deserialize(JsonParser jp, DeserializationContext ctxt)
57
57
/* Unit tests
58
58
/**********************************************************************
59
59
*/
60
+
61
+ final ObjectMapper MAPPER = new ObjectMapper ();
60
62
61
63
public void testNaN () throws Exception
62
64
{
63
- ObjectMapper m = new ObjectMapper ();
64
- Float result = m .readValue (" \" NaN\" " , Float .class );
65
+ Float result = MAPPER .readValue (" \" NaN\" " , Float .class );
65
66
assertEquals (Float .valueOf (Float .NaN ), result );
66
67
67
- Double d = m .readValue (" \" NaN\" " , Double .class );
68
+ Double d = MAPPER .readValue (" \" NaN\" " , Double .class );
68
69
assertEquals (Double .valueOf (Double .NaN ), d );
69
70
70
- Number num = m .readValue (" \" NaN\" " , Number .class );
71
+ Number num = MAPPER .readValue (" \" NaN\" " , Number .class );
71
72
assertEquals (Double .valueOf (Double .NaN ), num );
72
73
}
73
74
74
75
public void testDoubleInf () throws Exception
75
76
{
76
- ObjectMapper m = new ObjectMapper ();
77
- Double result = m .readValue (" \" " +Double .POSITIVE_INFINITY +"\" " , Double .class );
77
+ Double result = MAPPER .readValue (" \" " +Double .POSITIVE_INFINITY +"\" " , Double .class );
78
78
assertEquals (Double .valueOf (Double .POSITIVE_INFINITY ), result );
79
79
80
- result = m .readValue (" \" " +Double .NEGATIVE_INFINITY +"\" " , Double .class );
80
+ result = MAPPER .readValue (" \" " +Double .NEGATIVE_INFINITY +"\" " , Double .class );
81
81
assertEquals (Double .valueOf (Double .NEGATIVE_INFINITY ), result );
82
82
}
83
83
84
84
// [JACKSON-349]
85
85
public void testEmptyAsNumber () throws Exception
86
86
{
87
- ObjectMapper m = new ObjectMapper ();
88
- assertNull (m .readValue (quote ("" ), Integer .class ));
89
- assertNull (m .readValue (quote ("" ), Long .class ));
90
- assertNull (m .readValue (quote ("" ), Float .class ));
91
- assertNull (m .readValue (quote ("" ), Double .class ));
92
- assertNull (m .readValue (quote ("" ), BigInteger .class ));
93
- assertNull (m .readValue (quote ("" ), BigDecimal .class ));
87
+ assertNull (MAPPER .readValue (quote ("" ), Integer .class ));
88
+ assertNull (MAPPER .readValue (quote ("" ), Long .class ));
89
+ assertNull (MAPPER .readValue (quote ("" ), Float .class ));
90
+ assertNull (MAPPER .readValue (quote ("" ), Double .class ));
91
+ assertNull (MAPPER .readValue (quote ("" ), BigInteger .class ));
92
+ assertNull (MAPPER .readValue (quote ("" ), BigDecimal .class ));
94
93
}
95
94
96
95
// // Tests for [JACKSON-668]
97
-
96
+
98
97
public void testDeserializeDecimalHappyPath () throws Exception {
99
- ObjectMapper mapper = new ObjectMapper ();
100
98
String json = "{\" defaultValue\" : { \" value\" : 123 } }" ;
101
- MyBeanHolder result = mapper .readValue (json , MyBeanHolder .class );
99
+ MyBeanHolder result = MAPPER .readValue (json , MyBeanHolder .class );
102
100
assertEquals (BigDecimal .valueOf (123 ), result .defaultValue .value .decimal );
103
101
}
104
102
105
103
public void testDeserializeDecimalProperException () throws Exception {
106
- ObjectMapper mapper = new ObjectMapper ();
107
104
String json = "{\" defaultValue\" : { \" value\" : \" 123\" } }" ;
108
105
try {
109
- mapper .readValue (json , MyBeanHolder .class );
106
+ MAPPER .readValue (json , MyBeanHolder .class );
110
107
fail ("should have raised exception" );
111
108
} catch (JsonProcessingException e ) {
112
109
verifyException (e , "not numeric" );
113
110
}
114
111
}
115
112
116
113
public void testDeserializeDecimalProperExceptionWhenIdSet () throws Exception {
117
- ObjectMapper mapper = new ObjectMapper ();
118
114
String json = "{\" id\" : 5, \" defaultValue\" : { \" value\" : \" 123\" } }" ;
119
115
try {
120
- MyBeanHolder result = mapper .readValue (json , MyBeanHolder .class );
116
+ MyBeanHolder result = MAPPER .readValue (json , MyBeanHolder .class );
121
117
fail ("should have raised exception instead value was set to " + result .defaultValue .value .decimal .toString ());
122
118
} catch (JsonProcessingException e ) {
123
119
verifyException (e , "not numeric" );
124
120
}
125
121
}
122
+
123
+ // And then [databind#852]
124
+ public void testScientificNotationForString () throws Exception
125
+ {
126
+ Object ob = MAPPER .readValue ("\" 3E-8\" " , Number .class );
127
+ assertEquals (Double .class , ob .getClass ());
128
+ ob = MAPPER .readValue ("\" 3e-8\" " , Number .class );
129
+ assertEquals (Double .class , ob .getClass ());
130
+ ob = MAPPER .readValue ("\" 300000000\" " , Number .class );
131
+ assertEquals (Integer .class , ob .getClass ());
132
+ ob = MAPPER .readValue ("\" 123456789012\" " , Number .class );
133
+ assertEquals (Long .class , ob .getClass ());
134
+ }
126
135
}
0 commit comments