Reproduce支持Map类型

This commit is contained in:
redkale
2023-08-04 21:22:33 +08:00
parent 82b64c2e38
commit f1a7c4588b
3 changed files with 202 additions and 13 deletions

View File

@@ -4,7 +4,8 @@
package org.redkale.test.util;
import java.util.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.*;
import org.redkale.convert.json.JsonConvert;
import org.redkale.util.*;
/**
@@ -17,6 +18,8 @@ public class ReproduceTest {
ReproduceTest test = new ReproduceTest();
test.run1();
test.run2();
test.run3();
test.run4();
}
@Test
@@ -26,7 +29,10 @@ public class ReproduceTest {
bean.time = 55555L;
bean.setName("haha");
bean.setMap(Utility.ofMap("aa", "bbb"));
System.out.println(Reproduce.copy(Map.class, bean));
Map map = new TreeMap(Reproduce.copy(Map.class, bean));
System.out.println(JsonConvert.root().convertTo(map));
TreeMap rs = Reproduce.copy(TreeMap.class, bean);
Assertions.assertEquals(bean.toString(), JsonConvert.root().convertTo(rs));
}
@Test
@@ -36,6 +42,35 @@ public class ReproduceTest {
bean.time = 55555L;
bean.setName("haha");
bean.setMap(Utility.ofMap("aa", "bbb"));
System.out.println(Reproduce.load(Map.class, TestInterface.class).apply(new HashMap(), bean));
TreeMap rs = new TreeMap();
Reproduce.load(Map.class, TestInterface.class).apply(rs, bean);
System.out.println(JsonConvert.root().convertTo(rs));
}
@Test
public void run3() throws Exception {
Map map = new LinkedHashMap();
map.put("name", "haha");
map.put("time", "55555");
map.put("id", "222");
map.put("map", Utility.ofMap("aa", "bbb"));
TestBean bean = new TestBean();
Reproduce.load(TestInterface.class, Map.class).apply(bean, map);
Assertions.assertEquals("{\"id\":222,\"map\":{\"aa\":\"bbb\"},\"time\":0}", JsonConvert.root().convertTo(bean));
}
@Test
public void run4() throws Exception {
TestBean bean = new TestBean();
Map map = new TreeMap();
map.put("name", "haha");
map.put("time", "55555");
map.put("id", "222");
map.put("map", Utility.ofMap("aa", "bbb"));
Reproduce.load(TestBean.class, Map.class).apply(bean, map);
System.out.println(JsonConvert.root().convertTo(bean));
map.put("time", 55555L);
map.put("id", 222);
Assertions.assertEquals(bean.toString(), JsonConvert.root().convertTo(map));
}
}

View File

@@ -6,6 +6,7 @@
package org.redkale.test.util;
import java.util.Map;
import org.redkale.convert.json.JsonConvert;
/**
*
@@ -43,4 +44,8 @@ public class TestBean extends TestABean implements TestInterface {
this.map = map;
}
@Override
public String toString() {
return JsonConvert.root().convertTo(this);
}
}