This commit is contained in:
Looly
2024-08-03 12:40:38 +08:00
parent e487d924cb
commit 7f60318dd8
19 changed files with 286 additions and 170 deletions

View File

@@ -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());
}
}

View File

@@ -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);
}

View File

@@ -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());

View File

@@ -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());
}
}

View File

@@ -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