2

Perhaps I'm completely misunderstanding the purpose of JaVers, but I'm struggling here.

I got this POJO with a few nested subclasses, and I would like to create a new instance of that object ONLY containing the differences between two other instances, every matching field should stay null in the new class. Here is what I mean:

public class RootClass {
  private String someString;
  private String someOtherString;
  private ANestedClass aNestedClass;
  
  public RootClass(String someString, String someOtherString, ANestedClass aNestedClass) {
    this.someString = someString;
    this.someOtherString = someOtherString;
    this.aNestedClass = aNestedClass;
  }
  
  public static class ANestedClass {
    private String someNestedString;
    private String someOtherNestedString;
    
    public ANestedClass(String someNestedString, String someOtherNestedString) {
      this.someNestedString = someNestedString;
      this.someOtherNestedString = someOtherNestedString;
    }
  }
}

public RootClass getDifferenceObject() {
  RootClass a = new RootClass("foo", "bar", new ANestedClass("hello", "world"));
  RootClass b = new RootClass("foo", "blabla", new ANestedClass("hello", "earth");
  
  Javers javers = JaversBuilder.javers().withListCompareAlgorithm(ListCompareAlgorithm.LEVENSHTEIN_DISTANCE).build();
  Diff compare = javers.compare(a, b);
  
  // now convert this somehow
  RootClass abDiff = ...;
  
  assert(abDiff.someString == null);
  assert(abDiff.someOtherString.equals("blabla"));
  assert(abDiff.aNestedClass.someNestedString == null);
  assert(abDiff.aNestedClass.someOtherNestedString.equals("earth"));
}

Is this even possible with JaVers? I'm happy to pick a different library as well.

Selbi
  • 813
  • 7
  • 23

0 Answers0