W
W
web_dev2014-10-22 13:54:47
Java
web_dev, 2014-10-22 13:54:47

Compare, get difference and merge two complex java-objects generated using "jaxb"?

Hello, the problem is the following.
When updating (changing) an object, you need to compare it with the current one and replace the changed data. Simply replacing the object and eventually saving it (due to certain reasons) will not work.

To compare objects, I tried 2 libraries, they could not process the object.
https://github.com/SQiShER/java-object-diff
javers.org I

compare like 2 XML - I get a list with changes - and what to do next with this list - a lot of bicycles need to be reinvented.

In the case of writing equals methods and comparators, it is also time-consuming. And if a new model is suddenly generated after the changes, do not copy everything by hand ...

Will someone tell me something, ideas?

Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikolai Pavlov, 2014-10-22
@gurinderu

Why not just save the new object?

U
UbuRus, 2014-10-22
@UbuRus

Use a proxy on the object that is being modified. You can see in hibernate it's done.
upd. use reflection to compare each field of each object and the fields of nested objects, when finding non-equals fields (not objects), copy values ​​from one object to another. In this case, a general solution for this problem will be obtained.
upd2. spring.io/blog/2014/10/22/introducing-spring-sync

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question