This commit is contained in:
Looly
2022-04-28 03:20:23 +08:00
parent 17cd183722
commit 8e2c06c671
96 changed files with 175 additions and 167 deletions

View File

@@ -14,12 +14,12 @@ public class Issue488Test {
@Test
public void toBeanTest() {
String jsonStr = ResourceUtil.readUtf8Str("issue488.json");
ResultSuccess<List<EmailAddress>> result = JSONUtil.toBean(jsonStr,
new TypeReference<ResultSuccess<List<EmailAddress>>>() {}, false);
Assert.assertEquals("https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.emailAddress)", result.getContext());
List<EmailAddress> adds = result.getValue();
Assert.assertEquals("会议室101", adds.get(0).getName());
Assert.assertEquals("MeetingRoom101@abc.com", adds.get(0).getAddress());

View File

@@ -10,31 +10,31 @@ import cn.hutool.core.lang.TypeReference;
import cn.hutool.json.JSONUtil;
public class IssueIVMD5Test {
/**
* 测试泛型对象中有泛型字段的转换成功与否
*/
@Test
public void toBeanTest() {
String jsonStr = ResourceUtil.readUtf8Str("issueIVMD5.json");
TypeReference<BaseResult<StudentInfo>> typeReference = new TypeReference<BaseResult<StudentInfo>>() {};
BaseResult<StudentInfo> bean = JSONUtil.toBean(jsonStr, typeReference.getType(), false);
StudentInfo data2 = bean.getData2();
Assert.assertEquals("B4DDF491FDF34074AE7A819E1341CB6C", data2.getAccountId());
}
/**
* 测试泛型对象中有包含泛型字段的类型的转换成功与否比如List&lt;T&gt; list
*/
@Test
public void toBeanTest2() {
String jsonStr = ResourceUtil.readUtf8Str("issueIVMD5.json");
TypeReference<BaseResult<StudentInfo>> typeReference = new TypeReference<BaseResult<StudentInfo>>() {};
BaseResult<StudentInfo> bean = JSONUtil.toBean(jsonStr, typeReference.getType(), false);
List<StudentInfo> data = bean.getData();
StudentInfo studentInfo = data.get(0);
Assert.assertEquals("B4DDF491FDF34074AE7A819E1341CB6C", studentInfo.getAccountId());