mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -16,28 +16,41 @@
|
||||
|
||||
package org.dromara.hutool.json;
|
||||
|
||||
import lombok.Data;
|
||||
import org.dromara.hutool.core.io.resource.ResourceUtil;
|
||||
import org.dromara.hutool.core.lang.Console;
|
||||
import org.dromara.hutool.json.test.bean.ResultBean;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 测试在bean转换时使用BeanConverter,默认忽略转换失败的字段。
|
||||
* 现阶段Converter的问题在于,无法更细粒度的控制转换失败的范围,例如Bean的一个字段为List,
|
||||
* list任意一个item转换失败都会导致这个list为null。
|
||||
* <p>
|
||||
* TODO 需要在Converter中添加ConvertOption,用于更细粒度的控制转换规则
|
||||
* 转换失败,则在设置setIgnoreError(true)不报错
|
||||
*/
|
||||
public class Issue1200Test {
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void toBeanTest(){
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(ResourceUtil.readUtf8Str("issue1200.json"));
|
||||
Console.log(jsonObject);
|
||||
public void toBeanTest() {
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(
|
||||
ResourceUtil.readUtf8Str("issue1200.json"),
|
||||
JSONConfig.of().setIgnoreError(true));
|
||||
|
||||
final ResultBean resultBean = jsonObject.toBean(ResultBean.class);
|
||||
Console.log(resultBean);
|
||||
Assertions.assertNull(resultBean.getItems().get(0).get(0));
|
||||
}
|
||||
|
||||
@Data
|
||||
static
|
||||
class ResultBean {
|
||||
public List<List<List<ResultBean.ItemsBean>>> items;
|
||||
|
||||
@Data
|
||||
public static class ItemsBean {
|
||||
public ResultBean.ItemsBean.DetailBean detail;
|
||||
|
||||
@Data
|
||||
public static class DetailBean {
|
||||
public String visitorStatus;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -193,7 +193,7 @@ public class JSONArrayTest {
|
||||
|
||||
@Test
|
||||
public void toListWithErrorTest() {
|
||||
Assertions.assertThrows(ConvertException.class, ()->{
|
||||
Assertions.assertThrows(JSONException.class, ()->{
|
||||
final String json = "[['aaa',{'akey':'avalue','bkey':'bvalue'}]]";
|
||||
final JSONArray ja = JSONUtil.parseArray(json);
|
||||
|
||||
|
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Hutool Team and hutool.cn
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.dromara.hutool.json.test.bean;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ResultBean {
|
||||
public List<List<List<ItemsBean>>> items;
|
||||
|
||||
@Data
|
||||
public static class ItemsBean {
|
||||
public DetailBean detail;
|
||||
|
||||
@Data
|
||||
public static class DetailBean {
|
||||
public String visitorStatus;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user