修复CopyOptions.setFieldValueEditor后生成null值setIgnoreNullValue无效问题\

This commit is contained in:
Looly
2024-08-22 12:05:18 +08:00
parent 8bc2677267
commit 41dc63b580
4 changed files with 187 additions and 101 deletions

View File

@@ -0,0 +1,41 @@
package org.dromara.hutool.core.bean.copier;
import org.dromara.hutool.core.bean.BeanUtil;
import org.dromara.hutool.core.util.ObjUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
/**
* setFieldValueEditor编辑后的值理应继续判断ignoreNullValue
*/
public class Issue3702Test {
@Test
void mapToMapTest() {
final Map<String,String> map= new HashMap<>();
map.put("a","");
map.put("b","b");
map.put("c","c");
map.put("d","d");
final Map<String,String> map2= new HashMap<>();
map2.put("a","a1");
map2.put("b","b1");
map2.put("c","c1");
map2.put("d","d1");
final CopyOptions option= CopyOptions.of()
.setIgnoreNullValue(true)
.setIgnoreError(true)
.setFieldEditor((entry)->{
if(ObjUtil.equals(entry.getValue(), "")){
entry.setValue(null);
}
return entry;
});
BeanUtil.copyProperties(map,map2,option);
Assertions.assertEquals("{a=a1, b=b, c=c, d=d}", map2.toString());
}
}

View File

@@ -1,20 +1,20 @@
package org.dromara.hutool.core.map;
import org.dromara.hutool.core.map.multi.DirectedWeightGraph;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
/**
* @author newshiJ
* @date 2024/8/14 17:07
*/
public class DirectedWeightGraphTest {
@Test
public void test1(){
DirectedWeightGraph<String> graph = new DirectedWeightGraph<>();
@Disabled
public void test1() {
final DirectedWeightGraph<String> graph = new DirectedWeightGraph<>();
graph.putEdge("A", "B", 14);
graph.putEdge("A", "C", 8);
graph.putEdge("A", "D", 12);
@@ -44,10 +44,10 @@ public class DirectedWeightGraphTest {
Map<String, DirectedWeightGraph.Path<String>> map = null;
try {
map = graph.bestPathMap("A");
map.forEach((k,v) -> {
map.forEach((k, v) -> {
System.out.println(v);
});
} catch (DirectedWeightGraph.NegativeRingException e) {
} catch (final DirectedWeightGraph.NegativeRingException e) {
e.printStackTrace();
}