mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-04 04:37:59 +08:00
XmlUtil增加xmlToBean重载,支持CopyOptions参数
This commit is contained in:
parent
4c00f6adb2
commit
b2f95c9281
@ -2,7 +2,7 @@
|
||||
# 🚀Changelog
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.30(2024-08-08)
|
||||
# 5.8.30(2024-08-09)
|
||||
|
||||
### 🐣新特性
|
||||
* 【core 】 Converter转换规则变更,空对象、空值转为Bean时,创建默认对象,而非null(issue#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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user