我正在解析 JSON 并遇到一个异常,说我的一个实体没有默认构造函数。这是代码:
public class MyPromosResponse extends BaseResponse {
public MyPromosResponseData response;
public MyPromosResponse() {
}
public TreeSet<Promo> getMyPromosResponseData() {
return new TreeSet<Promo>(response.getEvents());
}
@JsonIgnoreProperties(ignoreUnknown = true)
class MyPromosResponseData {
public ArrayList<Promo> events;
public ArrayList<Table1PromoData> Table1;
public MyPromosResponseData() {
}
public ArrayList<Promo> getEvents() {
return events;
}
ArrayList<Table1PromoData> getTable1() {
return Table1;
}
}
class Table1PromoData {
public int id;
public int eventid;
public int cardholderid;
public Table1PromoData() { // Here is the constructor.
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getEventid() {
return eventid;
}
public void setEventid(int eventid) {
this.eventid = eventid;
}
public int getCardholderid() {
return cardholderid;
}
public void setCardholderid(int cardholderid) {
this.cardholderid = cardholderid;
}
}
}
当我有Table1PromoData
一个嵌套类时,我有错误找不到默认构造函数,但是定义了一个公共构造函数。如果我将它移动到一个单独的文件中,一切都很好——lib 找到了构造函数。
为什么默认构造函数在我将其移动到单独的文件后变得可见?