mirror of
https://gitee.com/dromara/hutool.git
synced 2025-06-28 13:34:09 +08:00
修复JSONUtil.toBean()中将JSON数组字符串转Map对象返回错误问题(issue#3795@Github)
This commit is contained in:
parent
d11693fb2d
commit
50807c84d6
@ -17,6 +17,7 @@
|
||||
* 【extra 】 修复MailUtil发送html格式邮件无法正常展示图片问题(pr#1279@Gitee)
|
||||
* 【core 】 【可能的向下兼容问题】修复双引号转义符转义错误问题,修改规则后,对非闭合双引号字段的策略变更,如"aa,则被识别为aa(issue#IB5UQ8@Gitee)
|
||||
* 【extra 】 修复Sftp中传入Session重连时逻辑错误问题(issue#IB69U8@Gitee)
|
||||
* 【json 】 修复JSONUtil.toBean()中将JSON数组字符串转Map对象返回错误问题(issue#3795@Github)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.33(2024-11-05)
|
||||
|
@ -74,6 +74,11 @@ public class MapConverter extends AbstractConverter<Map<?, ?>> {
|
||||
}
|
||||
convertMapToMap((Map) value, map);
|
||||
} else if (BeanUtil.isBean(value.getClass())) {
|
||||
if(value.getClass().getName().equals("cn.hutool.json.JSONArray")){
|
||||
// issue#3795 增加JSONArray转Map错误检查
|
||||
throw new UnsupportedOperationException(StrUtil.format("Unsupported {} to Map.", value.getClass().getName()));
|
||||
}
|
||||
|
||||
map = BeanUtil.beanToMap(value);
|
||||
// 二次转换,转换键值类型
|
||||
map = convertInternal(map);
|
||||
|
17
hutool-json/src/test/java/cn/hutool/json/Issue3795Test.java
Normal file
17
hutool-json/src/test/java/cn/hutool/json/Issue3795Test.java
Normal file
@ -0,0 +1,17 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.lang.TypeReference;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Issue3795Test {
|
||||
@Test
|
||||
void toBeanTest() {
|
||||
String fieldMapping = "[{\"lable\":\"id\",\"value\":\"id\"},{\"lable\":\"name\",\"value\":\"name\"},{\"lable\":\"age\",\"value\":\"age\"}]";
|
||||
Assertions.assertThrows(UnsupportedOperationException.class, ()->{
|
||||
JSONUtil.toBean(fieldMapping, new TypeReference<Map<String, String>>() {}, false);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user