Search code examples
javajavers

Shallow copy in Javers


Javers by default creates a commit doing a deep traverse of the object to log. When you have very complex objects, with inherited properties from parent classes etc, it can be a pain to have to go through the whole graph and annotate each property you don't want logged.

Is there a way to specify by default that Javers should do a shallow traverse and only specify the specific properties that we want included in the commit? Or is there an annotation that we can apply to the class to say that for that class Javers should shallow log it? @ShallowReference doesn't do that it seems.

E.g. for an object like:

User
   Long id
   String username
   Person person
       String firstName
       String lastName

I want either an annotation that I can apply to the User class, or some global setting so that when I do javers.commit("admin", user) Javers logs only id and username.


Solution

  • There is no such annotation. All you can do in this case is to ignore person property or Person class using @DiffIgnore. Think about contribution, this annotation could be named @Shallow.