File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
main/java/org/springframework/ai/util/json
test/java/org/springframework/ai/util/json Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change 17
17
package org .springframework .ai .util .json ;
18
18
19
19
import java .lang .reflect .Type ;
20
+ import java .math .BigDecimal ;
20
21
21
22
import com .fasterxml .jackson .core .JsonProcessingException ;
22
23
import com .fasterxml .jackson .core .type .TypeReference ;
@@ -128,13 +129,15 @@ else if (javaType == Byte.class) {
128
129
return Byte .parseByte (value .toString ());
129
130
}
130
131
else if (javaType == Integer .class ) {
131
- return Integer .parseInt (value .toString ());
132
+ BigDecimal bigDecimal = new BigDecimal (value .toString ());
133
+ return bigDecimal .intValueExact ();
132
134
}
133
135
else if (javaType == Short .class ) {
134
136
return Short .parseShort (value .toString ());
135
137
}
136
138
else if (javaType == Long .class ) {
137
- return Long .parseLong (value .toString ());
139
+ BigDecimal bigDecimal = new BigDecimal (value .toString ());
140
+ return bigDecimal .longValueExact ();
138
141
}
139
142
else if (javaType == Double .class ) {
140
143
return Double .parseDouble (value .toString ());
Original file line number Diff line number Diff line change @@ -241,6 +241,20 @@ var record = new TestRecord("John", 30);
241
241
assertThat (value ).isEqualTo (new TestRecord ("John" , 30 ));
242
242
}
243
243
244
+ @ Test
245
+ void fromScientificNotationToInteger () {
246
+ var value = JsonParser .toTypedObject ("1.5E7" , Integer .class );
247
+ assertThat (value ).isInstanceOf (Integer .class );
248
+ assertThat (value ).isEqualTo (15_000_000 );
249
+ }
250
+
251
+ @ Test
252
+ void fromScientificNotationToLong () {
253
+ var value = JsonParser .toTypedObject ("1.5E12" , Long .class );
254
+ assertThat (value ).isInstanceOf (Long .class );
255
+ assertThat (value ).isEqualTo (1_500_000_000_000L );
256
+ }
257
+
244
258
record TestRecord (String name , Integer age ) {
245
259
}
246
260
You can’t perform that action at this time.
0 commit comments