mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
315890ddc2
commit
f66b5fe55e
@ -122,7 +122,7 @@ public interface JSON extends Converter, Cloneable, Serializable {
|
||||
* @since 4.0.6
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
default <T> T getByPath(final String expression, final Class<T> resultType){
|
||||
default <T> T getByPath(final String expression, final Type resultType){
|
||||
return (T) config().getConverter().convert(resultType, getByPath(expression));
|
||||
}
|
||||
|
||||
|
32
hutool-json/src/test/java/org/dromara/hutool/json/Pr3067Test.java
Executable file
32
hutool-json/src/test/java/org/dromara/hutool/json/Pr3067Test.java
Executable file
@ -0,0 +1,32 @@
|
||||
package org.dromara.hutool.json;
|
||||
|
||||
import lombok.Data;
|
||||
import org.dromara.hutool.core.io.resource.ResourceUtil;
|
||||
import org.dromara.hutool.core.reflect.TypeReference;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Pr3067Test {
|
||||
|
||||
@Test
|
||||
public void getListByPathTest1() {
|
||||
final JSONObject json = JSONUtil.parseObj(ResourceUtil.readUtf8Str("test_json_path_001.json"));
|
||||
final List<TestUser> resultList = json.getByPath("testUserList[1].testArray",
|
||||
new TypeReference<List<TestUser>>() {});
|
||||
|
||||
Assertions.assertNotNull(resultList);
|
||||
Assertions.assertEquals(2, resultList.size());
|
||||
Assertions.assertEquals("a", resultList.get(0).getUsername());
|
||||
Assertions.assertEquals("a-password", resultList.get(0).getPassword());
|
||||
Assertions.assertEquals("b", resultList.get(1).getUsername());
|
||||
Assertions.assertEquals("b-password", resultList.get(1).getPassword());
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class TestUser {
|
||||
private String username;
|
||||
private String password;
|
||||
}
|
||||
}
|
19
hutool-json/src/test/resources/test_json_path_001.json
Executable file
19
hutool-json/src/test/resources/test_json_path_001.json
Executable file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"testUserList": [
|
||||
{
|
||||
"testAbc": "123"
|
||||
},
|
||||
{
|
||||
"testArray": [
|
||||
{
|
||||
"username": "a",
|
||||
"password": "a-password"
|
||||
},
|
||||
{
|
||||
"username": "b",
|
||||
"password": "b-password"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user