Class BeanDiff

java.lang.Object
org.apache.juneau.utils.BeanDiff

@Bean(properties="v1,v2") public class BeanDiff extends Object
Utility class for comparing two versions of a POJO.

// Two beans to compare. MyBean bean1, bean2; // Get differences. BeanDiff beanDiff = BeanDiff.create(bean1, bean2).exclude("fooProperty").build(); // Check for differences. boolean hasDiff = beanDiff.hasDiffs(); JsonMap v1Diffs = beanDiff.getV1(); // Get version 1 differences. JsonMap v2Diffs = beanDiff.getV2(); // Get version 2 differences. // Display differences. System.err.println(beanDiff);

See Also:
  • Constructor Details

    • BeanDiff

      public BeanDiff(BeanContext bc, T first, T second, Set<String> include, Set<String> exclude)
      Constructor.
      Type Parameters:
      T - The bean types.
      Parameters:
      bc - The bean context to use for comparing beans.
      first - The first bean to compare.
      second - The second bean to compare.
      include - Optional properties to include in the comparison.
      If null, all properties are included.
      exclude - Optional properties to exclude in the comparison.
      If null, no properties are excluded.
  • Method Details

    • create

      public static <T> BeanDiff.Builder<T> create(T first, T second)
      Create a new builder for this class.
      Type Parameters:
      T - The bean types.
      Parameters:
      first - The first bean to compare.
      second - The second bean to compare.
      Returns:
      A new builder.
    • hasDiffs

      public boolean hasDiffs()
      Returns true if the beans had differences.
      Returns:
      true if the beans had differences.
    • getV1

      public JsonMap getV1()
      Returns the differences in the first bean.
      Returns:
      The differences in the first bean.
    • getV2

      public JsonMap getV2()
      Returns the differences in the second bean.
      Returns:
      The differences in the second bean.
    • toString

      public String toString()
      Overrides:
      toString in class Object