Skip to content

Commit ebbdeae

Browse files
Fix double support: Parse actual numeric values instead of returning hardcoded 0/0.0
- Fixed MapTypeAdapter.read() in GsonUtil.kt to parse and return actual numeric values - Previously all JSON numbers were replaced with hardcoded 0 (int) or 0.0 (double) - Now correctly parses integers to Long and doubles to Double with proper error handling - Added .intellijPlatform to .gitignore as recommended by build system Fixes double support functionality in JSON to Dart bean conversion.
1 parent 86981ef commit ebbdeae

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.idea
33
.qodana
44
build
5+
.intellijPlatform

src/main/kotlin/com/github/zhangruiyu/flutterjsonbeanfactory/utils/GsonUtil.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,19 @@ object GsonUtil {
120120
*/
121121
val dbNum = `in`.nextString()
122122
if (!dbNum.contains(".")) {
123-
//返回0是int
124-
0
123+
// 解析并返回实际的整数值
124+
try {
125+
dbNum.toLong()
126+
} catch (e: NumberFormatException) {
127+
0
128+
}
125129
} else {
126-
//返回double类型代表是double类型
127-
0.0
130+
// 解析并返回实际的浮点数值
131+
try {
132+
dbNum.toDouble()
133+
} catch (e: NumberFormatException) {
134+
0.0
135+
}
128136
}
129137
}
130138

0 commit comments

Comments
 (0)