Configuration.getList(final String path, Class<T> t) 的问题
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 5.7k
- PR merge metrics
- No merged PRs in 30d
Description
版本:datax_v202209
通过Configuration.getList转自定义对象时,获得的不是期望的对象,而是JSONObject
case :
~~~
public class User {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public static void main(String[] args) {
String json = "{\"users\":[{\"name\":\"user1\"},{ \"name\":\"user2\"}]}";
Configuration userConf = Configuration.from(json);
System.out.println(userConf);
List users = userConf.getList("users", User.class);
System.out.println(users.get(0).getName());
System.out.println(json);
}
}
~~~
ERROR:
~~~
{"users":[{"name":"user1"},{"name":"user2"}]}
Exception in thread "main" java.lang.ClassCastException: class com.alibaba.fastjson.JSONObject cannot be cast to class datax.User (com.alibaba.fastjson.JSONObject and datax.User are in unnamed module of loader 'app')
at datax.User.main(User.java:24)
~~~

Contributor guide
No contributing guide indexed for this repository
Research direction
Start at Configuration.getList(String path, Class t) and reproduce the supplied User example from the issue. Check why the list elements remain fastjson JSONObject instances instead of User objects; done means users.get(0).getName() runs successfully without ClassCastException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100