我有以下域模型。NB Jackson @JsonView 字段注释:
public interface JSONInvoiceBasicView {
}
public interface JSONInvoiceWithLinesView extends JSONInvoiceBasicView {
}
public interface JSONInvoiceWithLinesViewExt extends JSONInvoiceWithLinesView {
}
}
@PersistenceUnit(unitName="ERP_PU")
@Entity
@Table(name="INVOICE")
public class Invoice extends FrameworkEntity {
@Id
@SequenceGenerator(name = "PK_INVOICE_GEN", sequenceName = "PK_INVOICE_GEN", allocationSize=1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PK_INVOICE_GEN")
@Column(name = "ID")
@JsonView(JSONInvoiceView.JSONInvoiceBasicView.class)
private Long id;
@OneToMany(mappedBy="invoiceLine", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JsonView(JSONInvoiceView.JSONInvoiceWithLinesView.class)
@JsonManagedReference
private List<InvoiceLine> lines = new ArrayList<InvoiceLine>();
@Temporal(TemporalType.DATE)
@Column(name = "DATE")
@JsonView(JSONInvoiceView.JSONInvoiceBasicView.class)
private Date startDate;
//...
}
@PersistenceUnit(unitName="ERP_PU")
@Entity
@Table(name="INVOICE_LINE")
public class InvoiceLine extends FrameworkEntity {
@Id
@Column(name = "ID")
@JsonView(JSONInvoiceView.JSONInvoiceWithLinesView.class)
private Long id;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinColumn(name="FK_INVOICE")
@JsonBackReference
private Invoice invoice;
@Column(name = "AMOUNT")
@JsonView(JSONInvoiceView.JSONInvoiceWithLinesView.class)
private BigDecimal amount;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinColumn(name="FK_GOOD")
@JsonView(JSONInvoiceView.JSONInvoiceWithLinesExtView.class)
private Good good;
//...
}
@PersistenceUnit(unitName="ERP_PU")
@Entity
@Table(name="GOOD")
public class Good extends FrameworkEntity {
@Id
@Column(name = "ID")
private Long id;
@Column(name = "DESCRIPTION", length=200)
private String description;
//...
}
所以 - 我的问题是我只检索整个对象图的子图,例如,只有带有注释的字段的 Invoice 和 InvoiceLine 实体@JsonView(JSONInvoiceView.JSONInvoiceWithLinesView.class)
,即我没有更进一步,我没有检索 invoice.invoiceLine[i].good 实体。我的问题是 -我可以修剪 JaVers 差异过程,我可以要求 JaVers 仅比较对象图的子集 - 例如用 注释的子集@JsonView(JSONInvoiceView.JSONInvoiceWithLinesView.class)
吗?
我的问题提到了实体字段上的 Jackson @JsonView 注释,但我猜 - 如果 JaVers 支持对观察到的属性进行这种过滤,那么这种过滤可以通过任何适合字段/属性的注释集来完成 - 无论是 Jackson 还是自定义创建的。
我听说过@DiffIgnore JaVers 注释,我正在寻找这种机制的泛化和精简。
我的场景是 - 我正在检索子图,我将 ir 发送到 Angular 前端,然后我从 Angular 获取更新的子图,我想将它合并回我的后端。