Search code examples
javajavabeans

Is there a way to know which properties are different between two beans?


I would like to persist changes made to my beans in a fashion similar to what Hibernate Envers does (but i can't use Envers, as i'm not connected to a JDBC back-end).

So, for that, i would like to know, between two instances of a given bean class, which properties have different values.

To be more clear, when given beans A and B, I would like to have a method ... say ... diff(A, B), that will output me a list (or map) linking properties to their old/new values.

Something like

<BeanClass> Collection<Field, Entry<Object, Object> diff(BeanClass a, BeanClass b)

Is there a library to do that in the Java world ?


Solution

  • Well, the solution was to use java-object-diff, which provides a visitable tree of differences between objects. As a consequence, we ended up using that library with great success.