This commit is contained in:
Looly
2024-09-23 15:08:20 +08:00
parent ff187f6fde
commit 2872f15e91
49 changed files with 796 additions and 600 deletions

View File

@@ -35,7 +35,12 @@ public class Issue1200Test {
JSONConfig.of().setIgnoreError(true));
final ResultBean resultBean = jsonObject.toBean(ResultBean.class);
Assertions.assertNull(resultBean.getItems().get(0).get(0));
// json对象转ItemsBean但是字段对应不上保留空对象
Assertions.assertNull(resultBean.getItems().get(0).get(0).get(0).getDetail());
// 字符串转对象失败为null
Assertions.assertNull(resultBean.getItems().get(0).get(0).get(1));
Assertions.assertNull(resultBean.getItems().get(0).get(0).get(2));
}
@Data

View File

@@ -21,14 +21,18 @@ import org.dromara.hutool.core.annotation.Alias;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* 兼容下划线模式的JSON转换为驼峰模式<br>
* 逻辑见JSONObjectValueProvider
*/
public class Issue867Test {
@Test
public void toBeanTest(){
public void toBeanTest() {
final String jsonStr = "{\"abc_1d\":\"123\",\"abc_d\":\"456\",\"abc_de\":\"789\"}";
final JSONObject json = JSONUtil.parseObj(jsonStr);
//Console.log(json);
final Test02 bean = JSONUtil.toBean(json,Test02.class);
final Test02 bean = JSONUtil.toBean(json, Test02.class);
Assertions.assertEquals("123", bean.getAbc1d());
Assertions.assertEquals("456", bean.getAbcD());
Assertions.assertEquals("789", bean.getAbcDe());

View File

@@ -17,7 +17,7 @@
package org.dromara.hutool.json;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.json.mapper.JSONValueMapper;
import org.dromara.hutool.json.serializer.JSONMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -27,7 +27,7 @@ public class IssueI9DX5HTest {
@Test
void xmlToJSONTest() {
final String xml = "<GoodMsg>你好</GoodMsg>";
final JSONValueMapper mapper = JSONValueMapper.of(JSONConfig.of(), entry -> {
final JSONMapper mapper = JSONMapper.of(JSONConfig.of(), entry -> {
entry.setKey(StrUtil.toUnderlineCase((CharSequence) entry.getKey()));
return true;
});

View File

@@ -17,6 +17,7 @@
package org.dromara.hutool.json;
import org.dromara.hutool.core.lang.Console;
import org.dromara.hutool.json.support.JSONStrFormatter;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;