mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
修复Pair反序列化报错问题
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user