/** * Compares JSON for equality. The expected object is converted to JSON * before comparison. Ignores order of sibling nodes and whitespaces. * * Please note that if you pass a String, it's parsed as JSON which can lead to an * unexpected behavior. If you pass in "1" it is parsed as a JSON containing * integer 1. If you compare it with a string it fails due to a different type. * If you want to pass in real string you have to quote it "\"1\"" or use * {@link #isStringEqualTo(String)}. * * If the string parameter is not a valid JSON, it is quoted automatically. * * @param expected * @return {@code this} object. * @see #isStringEqualTo(String) */ public JsonFluentAssert isEqualTo(Object expected) { Diff diff = createDiff(expected, configuration); diff.failIfDifferent(description); return this; }
/** * Compares JSON for equality. The expected object is converted to JSON * before comparison. Ignores order of sibling nodes and whitespaces. * * Please note that if you pass a String, it's parsed as JSON which can lead to an * unexpected behavior. If you pass in "1" it is parsed as a JSON containing * integer 1. If you compare it with a string it fails due to a different type. * If you want to pass in real string you have to quote it "\"1\"" or use * {@link #isStringEqualTo(String)}. * * If the string parameter is not a valid JSON, it is quoted automatically. * * @param expected * @return {@code this} object. * @see #isStringEqualTo(String) */ public JsonFluentAssert isEqualTo(Object expected) { Diff diff = createDiff(expected, configuration); diff.failIfDifferent(description); return this; }
/** * Compares JSON structure. Ignores values, only compares shape of the document and key names. * Is too lenient, ignores types, prefer IGNORING_VALUES option instead. * * @param expected * @return {@code this} object. * * @deprecated Use IGNORING_VALUES option instead */ @Deprecated public JsonFluentAssert hasSameStructureAs(Object expected) { Diff diff = createDiff(expected, configuration.withOptions(COMPARING_ONLY_STRUCTURE)); diff.failIfDifferent(); return this; }
/** * Compares JSON structure. Ignores values, only compares shape of the document and key names. * Is too lenient, ignores types, prefer IGNORING_VALUES option instead. * * @param expected * @return {@code this} object. * * @deprecated Use IGNORING_VALUES option instead */ @Deprecated public JsonFluentAssert hasSameStructureAs(Object expected) { Diff diff = createDiff(expected, configuration.withOptions(COMPARING_ONLY_STRUCTURE)); diff.failIfDifferent(); return this; }
/** * Fails if compared documents are equal. The expected object is converted to JSON * before comparison. Ignores order of sibling nodes and whitespaces. * * @param expected * @return {@code this} object. */ public JsonFluentAssert isNotEqualTo(Object expected) { Diff diff = createDiff(expected, configuration); if (diff.similar()) { failWithMessage("JSON is equal."); } return this; }
/** * Fails if compared documents are equal. The expected object is converted to JSON * before comparison. Ignores order of sibling nodes and whitespaces. * * @param expected * @return {@code this} object. */ public JsonFluentAssert isNotEqualTo(Object expected) { Diff diff = createDiff(expected, configuration); if (diff.similar()) { failWithMessage("JSON is equal."); } return this; }