@@ -83,7 +83,7 @@ public static JsonNodeFactory withExactBigDecimals(boolean bigDecimalExact)
83
83
{
84
84
return bigDecimalExact ? decimalsAsIs : decimalsNormalized ;
85
85
}
86
-
86
+
87
87
/*
88
88
/**********************************************************
89
89
/* Factory methods for literal values
@@ -171,16 +171,25 @@ public ValueNode numberNode(Integer value) {
171
171
* that expresses given 64-bit integer value
172
172
*/
173
173
@ Override
174
- public NumericNode numberNode (long v ) { return LongNode .valueOf (v ); }
175
-
174
+ public NumericNode numberNode (long v ) {
175
+ if (_inIntRange (v )) {
176
+ return IntNode .valueOf ((int ) v );
177
+ }
178
+ return LongNode .valueOf (v );
179
+ }
180
+
176
181
/**
177
182
* Alternate factory method that will handle wrapper value, which may be null.
178
183
* Due to possibility of null, returning type is not guaranteed to be
179
184
* {@link NumericNode}, but just {@link ValueNode}.
180
185
*/
181
186
@ Override
182
187
public ValueNode numberNode (Long value ) {
183
- return (value == null ) ? nullNode () : LongNode .valueOf (value .longValue ());
188
+ long l = value .longValue ();
189
+ if (_inIntRange (l )) {
190
+ return IntNode .valueOf ((int ) l );
191
+ }
192
+ return (value == null ) ? nullNode () : LongNode .valueOf (l );
184
193
}
185
194
186
195
/**
@@ -322,5 +331,18 @@ public BinaryNode binaryNode(byte[] data, int offset, int length) {
322
331
*/
323
332
@ Deprecated
324
333
public POJONode POJONode (Object pojo ) { return new POJONode (pojo ); }
334
+
335
+ /*
336
+ /**********************************************************
337
+ /* Helper methods
338
+ /**********************************************************
339
+ */
340
+
341
+ protected boolean _inIntRange (long l )
342
+ {
343
+ int i = (int ) l ;
344
+ long l2 = (long ) i ;
345
+ return (l2 == l );
346
+ }
325
347
}
326
348
0 commit comments