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

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

    Nested Classes 
    Modifier and Type Class Description
    static class  JsonAssert.ConfigurableJsonAssert
    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
    @NotNull JsonAssert and​(@NotNull 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) );
    @NotNull 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.
    @NotNull org.assertj.core.api.AbstractStringAssert<?> asString()  
    void isAbsent()
    Asserts that given node is absent.
    @NotNull org.assertj.core.api.ListAssert<Object> isArray()
    Asserts that given node is present and is of type array.
    @NotNull org.assertj.core.api.BooleanAssert isBoolean()
    Asserts that given node is present and is of type boolean.
    @NotNull JsonAssert isEqualTo​(@Nullable Object expected)
    Compares JSONs.
    org.assertj.core.api.BigIntegerAssert isIntegralNumber()
    Asserts that the value is an integer.
    @NotNull JsonAssert isNotNull()
    Asserts that given node is present and is not null.
    void isNull()
    Asserts that given node is present and is null.
    @NotNull org.assertj.core.api.BigDecimalAssert isNumber()
    Asserts that given node is present and is of type number.
    @NotNull org.assertj.core.api.MapAssert<String,​Object> isObject()
    Asserts that given node is present and is of type object.
    @NotNull JsonAssert isPresent()
    Asserts that given node is present.
    @NotNull org.assertj.core.api.StringAssert isString()
    Asserts that given node is present and is of type string.
    @NotNull org.assertj.core.api.UriAssert isUri()
    Asserts that given node is present and is URI.
    @NotNull JsonAssert node​(@NotNull String node)
    Moves comparison to given node.

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

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

    Methods inherited from class java.lang.Object

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

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

    as, as, describedAs
  • Method Details

    • node

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

      @NotNull public @NotNull JsonAssert and​(@NotNull @NotNull 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

      @NotNull public @NotNull JsonAssert isEqualTo​(@Nullable @Nullable Object expected)
      Compares JSONs.
      Specified by:
      isEqualTo in interface org.assertj.core.api.Assert<JsonAssert,​Object>
      Overrides:
      isEqualTo in class org.assertj.core.api.AbstractAssert<JsonAssert,​Object>
    • isObject

      @NotNull public @NotNull org.assertj.core.api.MapAssert<String,​Object> isObject()
      Asserts that given node is present and is of type object.
      Returns:
      MapAssert where the object is serialized as Map
    • isNumber

      @NotNull public @NotNull 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

      @NotNull public @NotNull 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

      @NotNull public @NotNull org.assertj.core.api.ListAssert<Object> isArray()
      Asserts that given node is present and is of type array.
      Returns:
    • isBoolean

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

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

      @NotNull public @NotNull 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

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

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

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

      @NotNull public @NotNull 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>