修复Pair反序列化报错问题

This commit is contained in:
Looly
2023-04-05 01:05:07 +08:00
parent 84e8456377
commit a97901f0e3
7 changed files with 283 additions and 82 deletions

View File

@@ -0,0 +1,30 @@
package cn.hutool.json;
import cn.hutool.core.lang.Pair;
import org.junit.Assert;
import org.junit.Test;
import java.util.AbstractMap;
import java.util.Map;
public class IssueI6SZYBTest {
@Test
public void pairTest() {
Pair<Integer,Integer> pair = Pair.of(1, 2);
String jsonStr = JSONUtil.toJsonStr(pair);
Assert.assertEquals("{\"key\":1,\"value\":2}", jsonStr);
final Pair bean = JSONUtil.toBean(jsonStr, Pair.class);
Assert.assertEquals(pair, bean);
}
@Test
public void entryTest() {
Map.Entry<String,Integer> pair = new AbstractMap.SimpleEntry<>("1", 2);
String jsonStr = JSONUtil.toJsonStr(pair);
Assert.assertEquals("{\"1\":2}", jsonStr);
final Map.Entry bean = JSONUtil.toBean(jsonStr, AbstractMap.SimpleEntry.class);
Assert.assertEquals(pair, bean);
}
}