8
8
import com .fasterxml .jackson .annotation .JsonFormat ;
9
9
10
10
import com .fasterxml .jackson .core .*;
11
+ import com .fasterxml .jackson .core .io .NumberOutput ;
11
12
import com .fasterxml .jackson .core .type .WritableTypeId ;
12
13
import com .fasterxml .jackson .databind .*;
13
14
import com .fasterxml .jackson .databind .annotation .JacksonStdImpl ;
@@ -225,19 +226,20 @@ public DoubleSerializer(Class<?> cls) {
225
226
226
227
@ Override
227
228
public void serialize (Object value , JsonGenerator gen ,
228
- SerializerProvider provider ) throws IOException {
229
+ SerializerProvider provider ) throws IOException
230
+ {
229
231
gen .writeNumber (((Double ) value ).doubleValue ());
230
232
}
231
233
232
234
// IMPORTANT: copied from `NonTypedScalarSerializerBase`
233
235
@ Override
234
236
public void serializeWithType (Object value , JsonGenerator g ,
235
237
SerializerProvider provider , TypeSerializer typeSer )
236
- throws IOException {
237
- // 08-Feb-2018, tatu: Except that as per [databind#2236], NaN values need
238
- // special handling
238
+ throws IOException
239
+ {
240
+ // 08-Feb-2018, tatu: [databind#2236], NaN values need special care
239
241
Double d = (Double ) value ;
240
- if (notFinite (d )) {
242
+ if (NumberOutput . notFinite (d )) {
241
243
WritableTypeId typeIdDef = typeSer .writeTypePrefix (g ,
242
244
// whether to indicate it's number or string is arbitrary; important it is scalar
243
245
typeSer .typeId (value , JsonToken .VALUE_NUMBER_FLOAT ));
@@ -248,9 +250,9 @@ public void serializeWithType(Object value, JsonGenerator g,
248
250
}
249
251
}
250
252
253
+ @ Deprecated // since 2.13, call NumberOutput.notFinite() directly
251
254
public static boolean notFinite (double value ) {
252
- // `jackson-core` has helper method in 3 but not yet
253
- return Double .isNaN (value ) || Double .isInfinite (value );
255
+ return NumberOutput .notFinite (value );
254
256
}
255
257
}
256
258
}
0 commit comments