我有以下复杂的 POJO 类发票
public class Measure {
private String id;
private Float value;
public String getId() { return id; }
public void setId(String id) { this.id = id; }
public Float getValue() { return value; }
public void setValue(Float value) { this.value = value; }
}
public class LineItem {
private Integer lineNumber;
private Measure shipped;
private List<LineItem> lineItems;
public Integer getLineNumber() { return lineNumber; }
public void setLineNumber(Integer lineNumber) { this.lineNumber = lineNumber; }
public Measure getShipped() { return shipped; }
public void setShipped(Measure shipped) { this.shipped = shipped; }
public List<LineItem> getLineItems() { return lineItems; }
public void setLineItems(List<LineItem> lineItems) { this.lineItems = lineItems; }
}
public class Invoice {
private String originUid;
private String vehicleUid;
private List<LineItem> lineItems;
public String getOriginUid() { return originUid; }
public void setOriginUid(String originUid) { this.originUid = originUid; }
public String getVehicleUid() { return vehicleUid; }
public void setVehicleUid(String vehicleUid) { this.vehicleUid = vehicleUid; }
public List<LineItem> getLineItems() { return lineItems; }
public void setLineItems(List<LineItem> lineItems) { this.lineItems = lineItems; }
}
现在我想深入遍历每个字段,包括 Invoice 对象中的嵌套对象,并使用反射更新它们。
我可以递归调用 updateIncomingObject()。但我需要知道如何将嵌套对象从字段中取出,如注释部分所示。
如何将字段转换为对象实例?
largeQ
相关分类