我正在解析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
作为嵌套类时,出现了无法找到默认构造函数的错误,但是已经定义了一个公共构造函数。如果我将其移到单独的文件中,一切都正常——库可以找到构造函数。
为什么将其移到单独的文件后,默认构造函数变得可见了呢?
static
。 - Sotirios Delimanolis