mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix bug
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JSONSupportTest {
|
||||
|
||||
/**
|
||||
* https://github.com/dromara/hutool/issues/1779
|
||||
* 在JSONSupport的JSONBeanParse中,如果使用json.toBean,会导致JSONBeanParse.parse方法反复递归调用,最终栈溢出<br>
|
||||
* 因此parse方法默认实现必须避开JSONBeanParse.parse调用。
|
||||
*/
|
||||
@Test
|
||||
public void parseTest() {
|
||||
String jsonstr = "{\n" +
|
||||
" \"location\": \"http://www.bejson.com\",\n" +
|
||||
" \"location\": \"https://hutool.cn\",\n" +
|
||||
" \"message\": \"这是一条测试消息\",\n" +
|
||||
" \"requestId\": \"123456789\",\n" +
|
||||
" \"traceId\": \"987654321\"\n" +
|
||||
@@ -18,7 +23,10 @@ public class JSONSupportTest {
|
||||
|
||||
|
||||
final TestBean testBean = JSONUtil.toBean(jsonstr, TestBean.class);
|
||||
Console.log(testBean);
|
||||
Assert.assertEquals("https://hutool.cn", testBean.getLocation());
|
||||
Assert.assertEquals("这是一条测试消息", testBean.getMessage());
|
||||
Assert.assertEquals("123456789", testBean.getRequestId());
|
||||
Assert.assertEquals("987654321", testBean.getTraceId());
|
||||
}
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
|
Reference in New Issue
Block a user