Class JsonAssert

java.lang.Object
org.assertj.core.api.AbstractAssert<JsonAssert, Object>
net.javacrumbs.jsonunit.assertj.JsonAssert
All Implemented Interfaces:
org.assertj.core.api.Assert<JsonAssert, Object>, org.assertj.core.api.Descriptable<JsonAssert>, org.assertj.core.api.ExtensionPoints<JsonAssert, Object>
Direct Known Subclasses:
JsonAssert.ConfigurableJsonAssert

@NullMarked public class JsonAssert extends org.assertj.core.api.AbstractAssert<JsonAssert, Object>
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    JsonAssert that can be configured to prevent mistakes like assertThatJson(...).isEqualsTo(...).when(...);
  • Field Summary

    Fields inherited from class org.assertj.core.api.AbstractAssert

    actual, info, myself, objects, throwUnsupportedExceptionOnEquals
  • Method Summary

    Modifier and Type
    Method
    Description
    and(JsonAssertion... assertions)
    Allows to do multiple comparisons on a document like assertThatJson("{\"test\":{\"a\":1, \"b\":2, \"c\":3}}").and( a -> a.node("test").isObject(), a -> a.node("test.b").isEqualTo(3) );
    <ASSERT extends org.assertj.core.api.AbstractAssert<?,?>>
    ASSERT
    asInstanceOf(org.assertj.core.api.InstanceOfAssertFactory<?,ASSERT> instanceOfAssertFactory)
     
    org.assertj.core.api.BigDecimalAssert
    Asserts that given node is present and is of type number or a string that can be parsed as a number.
    org.assertj.core.api.AbstractStringAssert<?>
     
    void
    Asserts that given node is absent.
    Asserts that given node is present and is of type array.
    org.assertj.core.api.BooleanAssert
    Asserts that given node is present and is of type boolean.
    isEqualTo(@Nullable Object expected)
    Compares JSONs.
    org.assertj.core.api.BigIntegerAssert
    Asserts that the value is an integer. 1 is an integer 1.0, 1.1, 1e3, 1e0, 1e-3 is not.
    Asserts that given node is present and is not null.
    void
    Asserts that given node is present and is null.
    org.assertj.core.api.BigDecimalAssert
    Asserts that given node is present and is of type number.
    Asserts that given node is present and is of type object.
    Asserts that given node is present.
    org.assertj.core.api.StringAssert
    Asserts that given node is present and is of type string.
    org.assertj.core.api.StringAssert
    Assert that the value is string and checks for equality.
    org.assertj.core.api.UriAssert
    Asserts that given node is present and is URI.
    node(String node)
    Moves comparison to given node.

    Methods inherited from class org.assertj.core.api.AbstractAssert

    actual, areEqual, asList, assertionError, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, doesNotMatch, doesNotMatch, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, hasToString, inBinary, inHexadecimal, is, isElementOfCustomAssert, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotOfAnyClassIn, isNotSameAs, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingEquals, usingEquals, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparison, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnError

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.assertj.core.api.Descriptable

    as, as, as, describedAs, describedAs
  • Method Details

    • node

      public JsonAssert node(String node)
      Moves comparison to given node. Second call navigates from the last position in the JSON.
    • and

      public JsonAssert and(JsonAssertion... assertions)
      Allows to do multiple comparisons on a document like assertThatJson("{\"test\":{\"a\":1, \"b\":2, \"c\":3}}").and( a -> a.node("test").isObject(), a -> a.node("test.b").isEqualTo(3) );
    • isEqualTo

      public JsonAssert isEqualTo(@Nullable Object expected)
      Compares JSONs. If expected is String it's first parsed as JSON. If it can't be parsed as JSON, it is treated as a String. If you want to disambiguate, specify the type first using isString(), isNumber() etc. Examples:
      • isEqualTo("{\"a\":1}") is parsed as JSON
      • isEqualTo("1") is parsed as number 1
      • isEqualTo("true") is parsed as boolean
      • isEqualTo("\"1\"") is parsed as String "1"
      • isEqualTo("a") is parsed as String "a"
      Specified by:
      isEqualTo in interface org.assertj.core.api.Assert<JsonAssert, Object>
      Overrides:
      isEqualTo in class org.assertj.core.api.AbstractAssert<JsonAssert, Object>
    • isStringEqualTo

      public org.assertj.core.api.StringAssert isStringEqualTo(String expected)
      Assert that the value is string and checks for equality. A shortcut for isString().isEqualTo(expected)
    • isObject

      public JsonMapAssert isObject()
      Asserts that given node is present and is of type object.
      Returns:
      MapAssert where the object is serialized as Map
    • isNumber

      public org.assertj.core.api.BigDecimalAssert isNumber()
      Asserts that given node is present and is of type number.
    • isIntegralNumber

      public org.assertj.core.api.BigIntegerAssert isIntegralNumber()
      Asserts that the value is an integer. 1 is an integer 1.0, 1.1, 1e3, 1e0, 1e-3 is not.
    • asNumber

      public org.assertj.core.api.BigDecimalAssert asNumber()
      Asserts that given node is present and is of type number or a string that can be parsed as a number.
    • isArray

      public JsonListAssert isArray()
      Asserts that given node is present and is of type array.
    • isBoolean

      public org.assertj.core.api.BooleanAssert isBoolean()
      Asserts that given node is present and is of type boolean.
    • isString

      public org.assertj.core.api.StringAssert isString()
      Asserts that given node is present and is of type string.
    • asString

      public org.assertj.core.api.AbstractStringAssert<?> asString()
      Specified by:
      asString in interface org.assertj.core.api.Assert<JsonAssert, Object>
      Overrides:
      asString in class org.assertj.core.api.AbstractAssert<JsonAssert, Object>
    • isNull

      public void isNull()
      Asserts that given node is present and is null.
      Specified by:
      isNull in interface org.assertj.core.api.Assert<JsonAssert, Object>
      Overrides:
      isNull in class org.assertj.core.api.AbstractAssert<JsonAssert, Object>
    • isUri

      public org.assertj.core.api.UriAssert isUri()
      Asserts that given node is present and is URI.
    • isPresent

      public JsonAssert isPresent()
      Asserts that given node is present.
    • isAbsent

      public void isAbsent()
      Asserts that given node is absent.
    • isNotNull

      public JsonAssert isNotNull()
      Asserts that given node is present and is not null.
      Specified by:
      isNotNull in interface org.assertj.core.api.Assert<JsonAssert, Object>
      Overrides:
      isNotNull in class org.assertj.core.api.AbstractAssert<JsonAssert, Object>
    • asInstanceOf

      public <ASSERT extends org.assertj.core.api.AbstractAssert<?,?>> ASSERT asInstanceOf(org.assertj.core.api.InstanceOfAssertFactory<?,ASSERT> instanceOfAssertFactory)
      Specified by:
      asInstanceOf in interface org.assertj.core.api.Assert<JsonAssert, Object>
      Overrides:
      asInstanceOf in class org.assertj.core.api.AbstractAssert<JsonAssert, Object>