XmlUtil增加xmlToBean重载,支持CopyOptions参数

This commit is contained in:
Looly 2024-08-09 09:16:57 +08:00
parent 4c00f6adb2
commit b2f95c9281
2 changed files with 28 additions and 11 deletions

View File

@ -2,7 +2,7 @@
# 🚀Changelog
-------------------------------------------------------------------------------------------------------------
# 5.8.30(2024-08-08)
# 5.8.30(2024-08-09)
### 🐣新特性
* 【core 】 Converter转换规则变更空对象、空值转为Bean时创建默认对象而非nullissue#3649@Github
@ -19,6 +19,7 @@
* 【poi 】 ExcelWriter.autoSizeColumn增加可选widthRatio参数可配置中文字符宽度倍数pr#3689@Github
* 【mail 】 MailAccount增加自定义参数支持issue#3687@Github
* 【mail 】 增加文字颜色与背景颜色色差设置pr#1252@gitee
* 【mail 】 XmlUtil增加xmlToBean重载支持CopyOptions参数issue#IAISBB@gitee
### 🐞Bug修复
* 【core 】 修复因RFC3986理解有误导致的UrlPath处理冒号转义问题issue#IAAE88@Gitee

View File

@ -1,6 +1,7 @@
package cn.hutool.core.util;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.exceptions.UtilException;
import cn.hutool.core.io.FileUtil;
@ -999,6 +1000,21 @@ public class XmlUtil {
* @since 5.2.4
*/
public static <T> T xmlToBean(Node node, Class<T> bean) {
return xmlToBean(node, bean, null);
}
/**
* XML转Java Bean
*
* @param <T> bean类型
* @param node XML节点
* @param bean bean类
* @param copyOptions Bean转换选项可选是否忽略错误等
* @return bean
* @see JAXBUtil#xmlToBean(String, Class)
* @since 5.8.30
*/
public static <T> T xmlToBean(Node node, Class<T> bean, CopyOptions copyOptions) {
final Map<String, Object> map = xmlToMap(node);
if (null != map && map.size() == 1) {
final String simpleName = bean.getSimpleName();
@ -1008,7 +1024,7 @@ public class XmlUtil {
return BeanUtil.toBean(map.get(nodeName), bean);
}
}
return BeanUtil.toBean(map, bean);
return BeanUtil.toBean(map, bean, copyOptions);
}
/**