我一直在努力让我的测试数据加载器在我的测试json文件中使用一个元素。我试过添加默认构造函数和各种不同的方法,但已达到我需要帮助的程度。
异常:失败:没有为类型[simple]找到合适的构造函数 type,class com ...截止日期]:无法从JSON对象实例化 (缺少默认构造函数或创建者,或者可能需要添加/启用 类型信息?)\ n在[来源: sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream@1d7041fb; line:14,column:4](通过参考链: 的java.util.ArrayList [0] - > COM ... .core.domain.representation.AdmissionsRepresentation [\ “期限\”] - > java.util.ArrayList中[0])“}
json看起来像这样:
[
{
"id" : "d5b6754a-f8aa-49e5-8e8c-d3f7ad0df2e3",
"rec" : 5153,
"acc" : 1389,
"app" : 12,
"rate" : 66,
"sat" : 2100,
"act" : 31,
"gpa" : 4.0,
"deadlines" : [
{
"type" : "Priority",
"day" : "1",
"month" : "3"
},
{
"type" : "General",
"day" : "15",
"month" : "7"
}
]
},
{
"id" : "d5b6754a-f8aa-49e5-8e8c-d3f7ad0df2e3",
"rec" : 5153,
"acc" : 1389,
"app" : 12,
"rate" : 66,
"sat" : 2100,
"act" : 31,
"gpa" : 4.0,
"deadlines" : [
{
"type" : "Priority",
"day" : "1",
"month" : "3"
},
{
"type" : "General",
"day" : "15",
"month" : "7"
}
]
}
]
错误中引用的两个类的片段
public class AdmissionsRepresentation {
private String id;
private String created;
private String lastModified;
private List<Deadline> deadlines = new ArrayList<>();
public AdmissionsRepresentation() {
}
public AdmissionsRepresentation(Admissions admissions) {
this();
fromDomain(admissions);
}
....
public void fromDomain(Admissions admissions) {
setId(admissions.collegeId());
List<Deadline> dl = admissions.deadlines();
for (int i = 0; i < dl.size(); i++) {
deadlines.add(dl.get(i));
}
}
public Admissions toDomain() {
ArrayList<Deadline> domainDeadlines = new ArrayList<Deadline>();
for (int i = 0; i < deadlines.size(); i++) {
domainDeadlines.add(deadlines.get(i));
}
Admissions admissions = null;
admissions = new AdmissionsBuilder().setId(this.id)...
.setDeadlines(domainDeadlines).build();
return admissions;
}
public class Deadline implements Serializable {
private static final long serialVersionUID = 1L;
// private Type type;
private String type;
private String label;
private String day;
private String month;
/*
* public enum Type {
* }
*/
//NOTE: I have tried removing this constructor and it seems to make no difference.
public Deadline() {
}
public Deadline(String type, String day, String month) {
this.type = type;
this.day = day;
this.month = month;
}
public String getType() {
return type;
}
public void setType(String type) {
System.out.println("setting type");
System.out.println("type: " + type.toString());
this.type = type;
// this.type = Type.valueOf(type);
}
}