5
5
import java .math .BigInteger ;
6
6
7
7
import com .fasterxml .jackson .core .JsonFactory ;
8
- import com .fasterxml .jackson .core .JsonParseException ;
9
8
import com .fasterxml .jackson .core .JsonParser .NumberType ;
10
9
import com .fasterxml .jackson .core .async .AsyncTestBase ;
10
+ import com .fasterxml .jackson .core .exc .InputCoercionException ;
11
11
import com .fasterxml .jackson .core .testsupport .AsyncReaderWrapper ;
12
12
import com .fasterxml .jackson .core .JsonToken ;
13
13
@@ -72,8 +72,10 @@ public void testToIntFailing() throws Exception
72
72
try {
73
73
p .getIntValue ();
74
74
fail ("Should not pass" );
75
- } catch (JsonParseException e ) {
75
+ } catch (InputCoercionException e ) {
76
76
verifyException (e , "out of range of int" );
77
+ assertEquals (JsonToken .VALUE_NUMBER_INT , e .getInputType ());
78
+ assertEquals (Integer .TYPE , e .getTargetType ());
77
79
}
78
80
long small = -1L + Integer .MIN_VALUE ;
79
81
p = createParser (String .valueOf (small ));
@@ -83,8 +85,10 @@ public void testToIntFailing() throws Exception
83
85
try {
84
86
p .getIntValue ();
85
87
fail ("Should not pass" );
86
- } catch (JsonParseException e ) {
88
+ } catch (InputCoercionException e ) {
87
89
verifyException (e , "out of range of int" );
90
+ assertEquals (JsonToken .VALUE_NUMBER_INT , e .getInputType ());
91
+ assertEquals (Integer .TYPE , e .getTargetType ());
88
92
}
89
93
90
94
// double -> error
@@ -94,17 +98,21 @@ public void testToIntFailing() throws Exception
94
98
try {
95
99
p .getIntValue ();
96
100
fail ("Should not pass" );
97
- } catch (JsonParseException e ) {
101
+ } catch (InputCoercionException e ) {
98
102
verifyException (e , "out of range of int" );
103
+ assertEquals (JsonToken .VALUE_NUMBER_INT , e .getInputType ());
104
+ assertEquals (Integer .TYPE , e .getTargetType ());
99
105
}
100
106
p = createParser (String .valueOf (small )+".0" );
101
107
assertToken (JsonToken .VALUE_NUMBER_FLOAT , p .nextToken ());
102
108
assertEquals ((double ) small , p .getDoubleValue ());
103
109
try {
104
110
p .getIntValue ();
105
111
fail ("Should not pass" );
106
- } catch (JsonParseException e ) {
112
+ } catch (InputCoercionException e ) {
107
113
verifyException (e , "out of range of int" );
114
+ assertEquals (JsonToken .VALUE_NUMBER_INT , e .getInputType ());
115
+ assertEquals (Integer .TYPE , e .getTargetType ());
108
116
}
109
117
110
118
// BigInteger -> error
@@ -114,17 +122,21 @@ public void testToIntFailing() throws Exception
114
122
try {
115
123
p .getIntValue ();
116
124
fail ("Should not pass" );
117
- } catch (JsonParseException e ) {
125
+ } catch (InputCoercionException e ) {
118
126
verifyException (e , "out of range of int" );
127
+ assertEquals (JsonToken .VALUE_NUMBER_INT , e .getInputType ());
128
+ assertEquals (Integer .TYPE , e .getTargetType ());
119
129
}
120
130
p = createParser (String .valueOf (small ));
121
131
assertToken (JsonToken .VALUE_NUMBER_INT , p .nextToken ());
122
132
assertEquals (BigInteger .valueOf (small ), p .getBigIntegerValue ());
123
133
try {
124
134
p .getIntValue ();
125
135
fail ("Should not pass" );
126
- } catch (JsonParseException e ) {
136
+ } catch (InputCoercionException e ) {
127
137
verifyException (e , "out of range of int" );
138
+ assertEquals (JsonToken .VALUE_NUMBER_INT , e .getInputType ());
139
+ assertEquals (Integer .TYPE , e .getTargetType ());
128
140
}
129
141
}
130
142
@@ -176,8 +188,10 @@ public void testToLongFailing() throws Exception
176
188
try {
177
189
p .getLongValue ();
178
190
fail ("Should not pass" );
179
- } catch (JsonParseException e ) {
191
+ } catch (InputCoercionException e ) {
180
192
verifyException (e , "out of range of long" );
193
+ assertEquals (JsonToken .VALUE_NUMBER_INT , e .getInputType ());
194
+ assertEquals (Long .TYPE , e .getTargetType ());
181
195
}
182
196
BigInteger small = BigInteger .valueOf (Long .MIN_VALUE ).subtract (BigInteger .TEN );
183
197
p = createParser (String .valueOf (small ));
@@ -186,8 +200,10 @@ public void testToLongFailing() throws Exception
186
200
try {
187
201
p .getLongValue ();
188
202
fail ("Should not pass" );
189
- } catch (JsonParseException e ) {
203
+ } catch (InputCoercionException e ) {
190
204
verifyException (e , "out of range of long" );
205
+ assertEquals (JsonToken .VALUE_NUMBER_INT , e .getInputType ());
206
+ assertEquals (Long .TYPE , e .getTargetType ());
191
207
}
192
208
}
193
209
0 commit comments