修复JsonUtil.toJsonStr对Boolean和Number返回错误问题(issue#4109@Github)。

This commit is contained in:
Looly
2025-10-29 18:50:10 +08:00
parent cbade4e239
commit 62f04b2c0d
4 changed files with 20 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
# 🚀Changelog
-------------------------------------------------------------------------------------------------------------
# 5.8.42(2025-10-28)
# 5.8.42(2025-10-29)
### 🐣新特性
* 【core 】 `ListUtil`增加`zip`方法pr#4052@Github
@@ -14,7 +14,8 @@
* 【extra 】 修复`JschSessionPool.remove`逻辑错误问题。
* 【db 】 修复`Dialect.psForCount`未传入Wrapper导致大小写问题issue#ID39G9@Gitee)。
* 【core 】 修复`PasswdStrength.check`indexOf逻辑问题pr#4114@Github)。
* 【htp 】 修复`HttpConnection.reflectSetMethod`反射在JDK9+权限问题issue#4109@Github)。
* 【http 】 修复`HttpConnection.reflectSetMethod`反射在JDK9+权限问题issue#4109@Github)。
* 【http 】 修复`JsonUtil.toJsonStr`对Boolean和Number返回错误问题issue#4109@Github)。
-------------------------------------------------------------------------------------------------------------
# 5.8.41(2025-10-12)

View File

@@ -359,6 +359,8 @@ public class JSONUtil {
}
if (obj instanceof CharSequence) {
return StrUtil.str((CharSequence) obj);
}else if(obj instanceof Boolean || obj instanceof Number) {
return obj.toString();
}
return toJsonStr(parse(obj, jsonConfig));
}

View File

@@ -0,0 +1,14 @@
package cn.hutool.json;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class IssueID418BTest {
@Test
void booleanToJsonTest() {
Boolean dd = true;
String jsonStr = JSONUtil.toJsonStr(dd);
Assertions.assertEquals("true", jsonStr);
}
}

View File

@@ -290,7 +290,7 @@ public class JSONUtilTest {
public void issue3540Test() {
Long userId = 10101010L;
final String jsonStr = JSONUtil.toJsonStr(userId);
assertEquals("{}", jsonStr);
assertEquals("10101010", jsonStr);
}
/**