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