add testcase

This commit is contained in:
wenshao 2025-03-13 19:58:50 +08:00
parent 9c08f49ea0
commit 395c52440b
2 changed files with 29 additions and 0 deletions

View File

@ -23,6 +23,11 @@ public class NonDefaulConstructorTest {
assertEquals(1001, vo.id);
assertEquals("bill", vo.name);
}
{
VO vo = objectReader.readObject(JSONReader.of("{'id':1001,'name':'bill'}"), 0);
assertEquals(1001, vo.id);
assertEquals("bill", vo.name);
}
{
Map map = new LinkedHashMap<>();
map.put("id", 1001);
@ -35,6 +40,22 @@ public class NonDefaulConstructorTest {
}
}
@Test
public void testBuild_1() throws Exception {
{
String str = "{\"id\":1001,\"name\":\"bill\"}";
VO vo = JSON.parseObject(str, VO.class);
assertEquals(1001, vo.id);
assertEquals("bill", vo.name);
}
{
String str = "{'id':1001,'name':'bill'}";
VO vo = JSON.parseObject(str, VO.class);
assertEquals(1001, vo.id);
assertEquals("bill", vo.name);
}
}
@Test
public void testBuild_2() throws Exception {
String str = JSONObject

View File

@ -3,6 +3,7 @@ package com.alibaba.fastjson2.codec;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONB;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONWriter;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
@ -35,6 +36,13 @@ public class NonDefaulConstructorTestTest2 {
assertEquals(3, a.id);
}
@Test
public void test_ab_1() {
String str = JSONObject.of("id", 3).fluentPut("name", "DataWorks").toString(JSONWriter.Feature.UseSingleQuotes);
B a = JSON.parseObject(str, B.class);
assertEquals(3, a.id);
}
public static class A {
private BigDecimal amount;
private Currency currency;