Reputation: 3056
I have the following domain model. NB Jackson @JsonView annotations for the fields:
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;
//...
}
So - my problem is that I am retrieving only subgraph of the entire object graph, e.g. only Invoice and InvoiceLine entities with the fields annotated with @JsonView(JSONInvoiceView.JSONInvoiceWithLinesView.class)
, i.e. I am not going further and I am not retrieving invoice.invoiceLine[i].good entity. My question is - can I prune the JaVers diff process, can I ask JaVers to compare only subset of the object graph - that subset that is annotated e.g. with @JsonView(JSONInvoiceView.JSONInvoiceWithLinesView.class)
?
My question mentions Jackson @JsonView annotations on the fields of entities but I guess - if JaVers support such filtering of observed properties, then this filtering can be done by any set of annotations approproate for fields/properites - be they Jackson or custom created.
I have heard about @DiffIgnore JaVers anotation, I am looking for the generalization and streamlining of this mechanism.
My scenario is - I am retrieving subgraph, I am sending ir to Angular fronent and then I am getting updated subgraph from Angular and I want to merge it back into my backend.
Upvotes: 2
Views: 1300
Reputation: 3496
There is a new annotation for that - @DiffInclude
. It works as a positive filter for class' properties.
@DiffInclude
— declares a property as visible by JaVers. Other properties in a given class are ignored (unless explicitly included). Including is opposite approach to Ignoring, like blacklisting vs whitelisting. You can use only one approach for a given class.
see https://javers.org/documentation/domain-configuration/#property-level-annotations
Upvotes: 3