mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
fix bug
This commit is contained in:
parent
16dfcf3154
commit
54420d8429
@ -3,7 +3,7 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 5.8.3.M1 (2022-06-09)
|
||||
# 5.8.3 (2022-06-10)
|
||||
|
||||
### 🐣新特性
|
||||
* 【extra 】 mail增加writeTimeout参数支持(issue#2355@Github)
|
||||
@ -16,6 +16,7 @@
|
||||
* 【json 】 修复Bean中存在bytes,无法转换问题(issue#2365@Github)
|
||||
* 【core 】 ArrayUtil.setOrAppend()传入空数组时,抛出异常(issue#I5APJE@Gitee)
|
||||
* 【extra 】 JschSessionPool修复空指针检查问题(issue#I5BK4D@Gitee)
|
||||
* 【core 】 修复使用ValueProvider中setFieldMapping无效问题(issue#I5B4R7@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -25,7 +25,7 @@ public class BeanToMapCopier extends AbsCopier<Object, Map> {
|
||||
* 构造
|
||||
*
|
||||
* @param source 来源Map
|
||||
* @param target 目标Bean对象
|
||||
* @param target 目标Map对象
|
||||
* @param targetType 目标泛型类型
|
||||
* @param copyOptions 拷贝选项
|
||||
*/
|
||||
|
@ -229,7 +229,8 @@ public class CopyOptions implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置拷贝属性的字段映射,用于不同的属性之前拷贝做对应表用
|
||||
* 设置拷贝属性的字段映射,用于不同的属性之前拷贝做对应表用<br>
|
||||
* 需要注意的是,当使用ValueProvider作为数据提供者时,这个映射是相反的,即fieldMapping中key为目标Bean的名称,而value是提供者中的key
|
||||
*
|
||||
* @param fieldMapping 拷贝属性的字段映射,用于不同的属性之前拷贝做对应表用
|
||||
* @return CopyOptions
|
||||
@ -241,7 +242,8 @@ public class CopyOptions implements Serializable {
|
||||
/**
|
||||
* 设置字段属性编辑器,用于自定义属性转换规则,例如驼峰转下划线等<br>
|
||||
* 此转换器只针对源端的字段做转换,请确认转换后与目标端字段一致<br>
|
||||
* 当转换后的字段名为null时忽略这个字段
|
||||
* 当转换后的字段名为null时忽略这个字段<br>
|
||||
* 需要注意的是,当使用ValueProvider作为数据提供者时,这个映射是相反的,即fieldMapping中key为目标Bean的名称,而value是提供者中的key
|
||||
*
|
||||
* @param fieldNameEditor 字段属性编辑器,用于自定义属性转换规则,例如驼峰转下划线等
|
||||
* @return CopyOptions
|
||||
|
@ -68,7 +68,7 @@ public class MapToBeanCopier<T> extends AbsCopier<Map<?, ?>, T> {
|
||||
}
|
||||
|
||||
// 检查目标字段可写性
|
||||
PropDesc tDesc = findPropDesc(targetPropDescMap, sKeyStr);
|
||||
final PropDesc tDesc = findPropDesc(targetPropDescMap, sKeyStr);
|
||||
if (null == tDesc || false == tDesc.isWritable(this.copyOptions.transientSupport)) {
|
||||
// 字段不可写,跳过之
|
||||
return;
|
||||
|
@ -49,6 +49,11 @@ public class ValueProviderToBeanCopier<T> extends AbsCopier<ValueProvider<String
|
||||
if (null == tFieldName) {
|
||||
return;
|
||||
}
|
||||
tFieldName = copyOptions.editFieldName(tFieldName);
|
||||
// 对key做转换,转换后为null的跳过
|
||||
if (null == tFieldName) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 无字段内容跳过
|
||||
if(false == source.containsKey(tFieldName)){
|
||||
|
@ -815,4 +815,29 @@ public class BeanUtilTest {
|
||||
public static class WkCrmCustomer{
|
||||
private LocalDateTime statusIdUpdateTime;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueProviderToBeanTest(){
|
||||
// https://gitee.com/dromara/hutool/issues/I5B4R7
|
||||
CopyOptions copyOptions = CopyOptions.create();
|
||||
Map<String, String> filedMap= new HashMap<>();
|
||||
filedMap.put("name", "sourceId");
|
||||
copyOptions.setFieldMapping(filedMap);
|
||||
TestPojo pojo = BeanUtil.toBean(TestPojo.class, new ValueProvider<String>() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
{
|
||||
map.put("sourceId", "123");
|
||||
}
|
||||
@Override
|
||||
public Object value(String key, Type valueType) {
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(String key) {
|
||||
return map.containsKey(key);
|
||||
}
|
||||
}, copyOptions);
|
||||
Assert.assertEquals("123", pojo.getName());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user