diff --git a/CHANGELOG.md b/CHANGELOG.md
index 67654e5180..83d92d8211 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@
### 🐣新特性
### 🐞Bug修复
+* 【json 】 修复`JSONUtil.wrap`忽略错误问题(issue#4210@Github)
-------------------------------------------------------------------------------------------------------------
# 5.8.43(2026-01-04)
diff --git a/hutool-json/src/main/java/cn/hutool/json/JSONUtil.java b/hutool-json/src/main/java/cn/hutool/json/JSONUtil.java
index 0051370f85..6ec902bb17 100755
--- a/hutool-json/src/main/java/cn/hutool/json/JSONUtil.java
+++ b/hutool-json/src/main/java/cn/hutool/json/JSONUtil.java
@@ -739,7 +739,7 @@ public class JSONUtil {
*
map =》 JSONObject
* standard property (Double, String, et al) =》 原对象
* 来自于java包 =》 字符串
- * 其它 =》 尝试包装为JSONObject,否则返回{@code null}
+ * 其它 =》 尝试包装为JSONObject,如果{@link JSONConfig#isIgnoreError()}为true时返回{@code null}, 否则抛出异常
*
*
* @param object 被包装的对象
@@ -805,7 +805,11 @@ public class JSONUtil {
// 默认按照JSONObject对待
return new JSONObject(object, jsonConfig);
} catch (final Exception exception) {
- return null;
+ // issue#4210 只有设置忽略错误时才返回null
+ if(jsonConfig.isIgnoreError()){
+ return null;
+ }
+ throw exception;
}
}
diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue4210Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue4210Test.java
new file mode 100644
index 0000000000..3a0813a4cd
--- /dev/null
+++ b/hutool-json/src/test/java/cn/hutool/json/Issue4210Test.java
@@ -0,0 +1,45 @@
+package cn.hutool.json;
+
+import cn.hutool.core.exceptions.InvocationTargetRuntimeException;
+import cn.hutool.core.lang.Console;
+import cn.hutool.core.lang.ObjectId;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.io.Serializable;
+
+public class Issue4210Test {
+
+ @Test
+ void setValueTest(){
+ final JSONObject jsonObject = new JSONObject();
+
+ final TestEntity entity = new TestEntity("张三", "社畜");
+ Assertions.assertThrows(InvocationTargetRuntimeException.class, () -> jsonObject.set("entity",entity));
+ }
+
+ @Data
+ public static class BaseEntity implements Serializable {
+
+ /**
+ * 实体唯一标识符
+ */
+ private String _id;
+ private ObjectId id;
+
+ public String get_id() {
+ return _id == null ? id.toString() : _id;
+ }
+ }
+
+ @EqualsAndHashCode(callSuper = true)
+ @Data
+ @AllArgsConstructor
+ public class TestEntity extends BaseEntity{
+ private String name;
+ private String desc;
+ }
+}