assertj と Jackson の JsonNode を組み合わせて使用しています。これまでのところ、私は使用してAssertions.assertThat(objectNode0).isEqualTo(objectNode1);
おり、すべて正常に動作しています。
ここで、比較でいくつかのフィールドを無視する必要がありusingRecursiveComparison
ます. これを克服する方法はありますか?ここに私のサンプルコードがあります:
public class Main {
public static void main(String[] args) {
ObjectMapper om = new ObjectMapper();
try {
JsonNode objectNode0 = om.readTree("{\"someNotImportantValue\":1,\"importantValue\":\"10\"}");
JsonNode objectNode1 = om.readTree("{\"someNotImportantValue\":15,\"importantValue\":\"1\"}");
boolean equals = objectNode0.equals(objectNode1);
System.out.println(equals); // prints false
//This works, but does not enable to ignore any field
//Assertions.assertThat(objectNode0).isEqualTo(objectNode1);
//We would expect this sentence to fail, since importantValue is still different, but it does not.
Assertions.assertThat(objectNode0).usingRecursiveComparison().ignoringFields("someNotImportantValue").isEqualTo(objectNode1);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
}