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 1717package org .springframework .ai .util .json ;
1818
1919import java .lang .reflect .Type ;
20+ import java .math .BigDecimal ;
2021
2122import com .fasterxml .jackson .core .JsonProcessingException ;
2223import com .fasterxml .jackson .core .type .TypeReference ;
@@ -128,13 +129,15 @@ else if (javaType == Byte.class) {
128129 return Byte .parseByte (value .toString ());
129130 }
130131 else if (javaType == Integer .class ) {
131- return Integer .parseInt (value .toString ());
132+ BigDecimal bigDecimal = new BigDecimal (value .toString ());
133+ return bigDecimal .intValueExact ();
132134 }
133135 else if (javaType == Short .class ) {
134136 return Short .parseShort (value .toString ());
135137 }
136138 else if (javaType == Long .class ) {
137- return Long .parseLong (value .toString ());
139+ BigDecimal bigDecimal = new BigDecimal (value .toString ());
140+ return bigDecimal .longValueExact ();
138141 }
139142 else if (javaType == Double .class ) {
140143 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);
241241 assertThat (value ).isEqualTo (new TestRecord ("John" , 30 ));
242242 }
243243
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+
244258 record TestRecord (String name , Integer age ) {
245259 }
246260
You can’t perform that action at this time.
0 commit comments