How to Achieve Field by Field Comparison Behaviour Without Recursively Traversing the Whole Object Graph #3352
Unanswered
raphaelNguyen
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Consider taking the opposite approach - of ignoring the fields you don't need to compare. I have similar requirements for my project, and this is what I went with:
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all,
I have a use case where I want to assert equal between 2 objects (e.g.
A
) according to a subset of the fields (e.g.i
andj
) on the objects. These objects are part of an object graph so there are a number of fields that I don't want to recurse into for this assertion (e.g.b
).Previously, I was able to get this behaviour via
.usingRecursiveComparison().comparingOnlyFieldsOfType(String.class, [...])
and then specifying a few field names to ignore. It never recurse into the object graph and only assert equality using the fields I'm concerned with. However, #3207 specified that this was not intended behaviour and fixed it. With the new behaviour, the assertion takes significantly longer as it has to traverse the very complex object graph.I've tried tweaking various settings in the recursive comparison configuration but have yet to be able to limit the traversal. I've also found that I might be able to achieve my desired behaviour with
.isEqualToComparingFieldByField()
but this have been deprecated in favour of.usingRecursiveComparison()
.My only recourse is if I extract all the fields I'm concerned with from the object and assert equality with them. This does have the drawback of not automatically taking into account new fields if I add them in the future. Without any better alternatives, this might be what I have to go with.
Can you please suggest if there might be a way for me to achieve the desired equality assertion behaviour with the current API?
Thank you very much for your time.
Beta Was this translation helpful? Give feedback.
All reactions