AssertJ
has isEqualToIgnoringGivenFields
and isEqualToComparingFieldByFieldRecursively
.
But, there is no way I can compare two objects recursively by ignoring some fields. As per this discussion, it must be in development.
How to still get my assert's return value to be compared recursively but ignoring some fields. Is it possible in any other library or can I do it somehow using AssertJ
?
With latest 'Recursive comparison api improvements' from AssertJ release 3.12.0 it's possible now to do a recursive comparison and ignore fields:
Assertions.assertThat(objActual)
.usingRecursiveComparison()
.ignoringFields("uniqueId", "otherId")
.ignoringFieldsMatchingRegexes(".*someId")
.ignoringOverriddenEqualsForTypes(MyData.class, MyDataItem.class)
.isEqualTo(objExpected);