mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
XmlUtil增加xmlToBean重载,支持CopyOptions参数
This commit is contained in:
parent
6082abff00
commit
ec38dcd5fa
@ -13,6 +13,7 @@
|
||||
package org.dromara.hutool.core.xml;
|
||||
|
||||
import org.dromara.hutool.core.bean.BeanUtil;
|
||||
import org.dromara.hutool.core.bean.copier.CopyOptions;
|
||||
import org.dromara.hutool.core.collection.CollUtil;
|
||||
import org.dromara.hutool.core.collection.ListUtil;
|
||||
import org.dromara.hutool.core.map.MapUtil;
|
||||
@ -60,10 +61,10 @@ public class XmlMapper {
|
||||
*
|
||||
* @param <T> bean类型
|
||||
* @param bean bean类
|
||||
* @param copyOptions 拷贝选线,可选是否忽略错误等
|
||||
* @return bean
|
||||
* @since 5.2.4
|
||||
*/
|
||||
public <T> T toBean(final Class<T> bean) {
|
||||
public <T> T toBean(final Class<T> bean, final CopyOptions copyOptions) {
|
||||
final Map<String, Object> map = toMap();
|
||||
if (null != map && map.size() == 1) {
|
||||
final String nodeName = CollUtil.getFirst(map.keySet());
|
||||
@ -72,7 +73,7 @@ public class XmlMapper {
|
||||
return BeanUtil.toBean(CollUtil.get(map.values(), 0), bean);
|
||||
}
|
||||
}
|
||||
return BeanUtil.toBean(map, bean);
|
||||
return BeanUtil.toBean(map, bean, copyOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,6 +13,7 @@
|
||||
package org.dromara.hutool.core.xml;
|
||||
|
||||
import org.dromara.hutool.core.bean.BeanUtil;
|
||||
import org.dromara.hutool.core.bean.copier.CopyOptions;
|
||||
import org.dromara.hutool.core.exception.HutoolException;
|
||||
import org.dromara.hutool.core.io.IORuntimeException;
|
||||
import org.dromara.hutool.core.io.IoUtil;
|
||||
@ -587,6 +588,7 @@ public class XmlUtil extends XmlConstants {
|
||||
}
|
||||
|
||||
// region ----- xmlToMap or xmlToBean
|
||||
|
||||
/**
|
||||
* XML转Java Bean<br>
|
||||
* 如果XML根节点只有一个,且节点名和Bean的名称一致,则直接转换子节点
|
||||
@ -598,7 +600,22 @@ public class XmlUtil extends XmlConstants {
|
||||
* @since 5.2.4
|
||||
*/
|
||||
public static <T> T xmlToBean(final Node node, final Class<T> beanClass) {
|
||||
return XmlMapper.of(node).toBean(beanClass);
|
||||
return xmlToBean(node, beanClass, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* XML转Java Bean<br>
|
||||
* 如果XML根节点只有一个,且节点名和Bean的名称一致,则直接转换子节点
|
||||
*
|
||||
* @param <T> bean类型
|
||||
* @param node XML节点
|
||||
* @param beanClass bean类
|
||||
* @param copyOptions 拷贝选线,可选是否忽略错误等
|
||||
* @return bean
|
||||
* @since 5.8.30
|
||||
*/
|
||||
public static <T> T xmlToBean(final Node node, final Class<T> beanClass, final CopyOptions copyOptions) {
|
||||
return XmlMapper.of(node).toBean(beanClass, copyOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -655,6 +672,7 @@ public class XmlUtil extends XmlConstants {
|
||||
// endregion
|
||||
|
||||
// region ----- toXml
|
||||
|
||||
/**
|
||||
* 将Map转换为XML格式的字符串
|
||||
*
|
||||
@ -846,6 +864,7 @@ public class XmlUtil extends XmlConstants {
|
||||
}
|
||||
|
||||
// region ----- append
|
||||
|
||||
/**
|
||||
* 在已有节点上创建子节点
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user