mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-30 12:47:58 +08:00
add test
This commit is contained in:
parent
6b45cfb7e2
commit
7df5a80e87
64
hutool-json/src/test/java/org/dromara/hutool/json/IssueI7M2GZTest.java
Executable file
64
hutool-json/src/test/java/org/dromara/hutool/json/IssueI7M2GZTest.java
Executable file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2023 looly(loolly@aliyun.com)
|
||||
* Hutool is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
package org.dromara.hutool.json;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.dromara.hutool.core.reflect.TypeReference;
|
||||
import org.dromara.hutool.json.serialize.JSONDeserializer;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* https://gitee.com/dromara/hutool/issues/I7M2GZ
|
||||
*/
|
||||
public class IssueI7M2GZTest {
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public static class JSONBeanParserImpl implements JSONDeserializer<JSONBeanParserImpl> {
|
||||
private String name;
|
||||
private Integer parsed;
|
||||
|
||||
@Override
|
||||
public JSONBeanParserImpl deserialize(final JSON json) {
|
||||
setName("new Object");
|
||||
setParsed(12);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class MyEntity<T> {
|
||||
private List<T> list;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toListTest() {
|
||||
final List<JSONBeanParserImpl> list = new ArrayList<>();
|
||||
list.add(new JSONBeanParserImpl("Object1", 1));
|
||||
|
||||
final MyEntity<JSONBeanParserImpl> entity = new MyEntity<>();
|
||||
entity.setList(list);
|
||||
|
||||
final String json = JSONUtil.toJsonStr(entity);
|
||||
//Console.log(json);
|
||||
final MyEntity<JSONBeanParserImpl> result = JSONUtil.toBean(json, new TypeReference<MyEntity<JSONBeanParserImpl>>() {});
|
||||
Assertions.assertEquals("new Object", result.getList().get(0).getName());
|
||||
Assertions.assertNotNull(result.getList().get(0).getParsed());
|
||||
Assertions.assertEquals(Integer.valueOf(12), result.getList().get(0).getParsed());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user