mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package org.dromara.hutool.json;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* https://github.com/dromara/hutool/issues/1399<br>
|
||||
* 异常SQLException实现了Iterable导致被识别为列表,可能造成死循环,此处按照字符串处理
|
||||
*/
|
||||
public class Issue1399Test {
|
||||
@Test
|
||||
void sqlExceptionTest() {
|
||||
final JSONObject set = JSONUtil.ofObj().set("error", new SQLException("test"));
|
||||
Assertions.assertEquals("{\"error\":\"java.sql.SQLException: test\"}", set.toString());
|
||||
}
|
||||
}
|
@@ -12,7 +12,6 @@
|
||||
|
||||
package org.dromara.hutool.json;
|
||||
|
||||
import org.dromara.hutool.core.lang.Console;
|
||||
import lombok.Data;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -33,7 +32,6 @@ public class Issue2090Test {
|
||||
test.setLocalDate(LocalDate.now());
|
||||
|
||||
final JSONObject json = JSONUtil.parseObj(test);
|
||||
Console.log(json);
|
||||
final TestBean test1 = json.toBean(TestBean.class);
|
||||
Assertions.assertEquals(test, test1);
|
||||
}
|
||||
|
@@ -337,8 +337,8 @@ public class JSONObjectTest {
|
||||
bean.setTestEnum(TestEnum.TYPE_B);
|
||||
|
||||
final JSONObject json = JSONUtil.parseObj(bean, false);
|
||||
// 枚举转换检查
|
||||
Assertions.assertEquals("TYPE_B", json.get("testEnum"));
|
||||
// 枚举转换检查,更新:枚举原样保存,在writer时调用toString。
|
||||
Assertions.assertEquals(TestEnum.TYPE_B, json.get("testEnum"));
|
||||
|
||||
final TestBean bean2 = json.toBean(TestBean.class);
|
||||
Assertions.assertEquals(bean.toString(), bean2.toString());
|
||||
|
@@ -0,0 +1,12 @@
|
||||
package org.dromara.hutool.json;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class Pr3507Test {
|
||||
@Test
|
||||
void writeClassTest() {
|
||||
final JSONObject set = JSONUtil.ofObj().set("name", Pr3507Test.class);
|
||||
Assertions.assertEquals("{\"name\":\"org.dromara.hutool.json.Pr3507Test\"}", set.toString());
|
||||
}
|
||||
}
|
@@ -20,12 +20,21 @@ import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class GlobalValueWriterMappingTest {
|
||||
public class GlobalValueWritersTest {
|
||||
|
||||
@BeforeEach
|
||||
public void init(){
|
||||
GlobalValueWriterMapping.put(CustomSubBean.class,
|
||||
(JSONValueWriter<CustomSubBean>) (writer, value) -> writer.writeRaw(String.valueOf(value.getId())));
|
||||
GlobalValueWriters.add(new JSONValueWriter() {
|
||||
@Override
|
||||
public void write(final JSONWriter writer, final Object value) {
|
||||
writer.writeRaw(String.valueOf(((CustomSubBean)value).getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(final Object value) {
|
||||
return value instanceof CustomSubBean;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
Reference in New Issue
Block a user