Class JsonAssert

java.lang.Object
org.assertj.core.api.AbstractAssert<JsonAssert,String>
com.devsoap.json.JsonAssert
All Implemented Interfaces:
org.assertj.core.api.Assert<JsonAssert,String>, org.assertj.core.api.Descriptable<JsonAssert>, org.assertj.core.api.ExtensionPoints<JsonAssert,String>

public class JsonAssert extends org.assertj.core.api.AbstractAssert<JsonAssert,String>
JSON Assertions
  • Field Summary

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

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

    Constructors
    Modifier
    Constructor
    Description
    protected
    Instantiates a new Json assert.
  • Method Summary

    Modifier and Type
    Method
    Description
    array(String fieldName)
    Get field as array
    <ITEM> org.assertj.core.api.ListAssert<ITEM>
    array(String fieldName, Class<ITEM> itemClass)
    Get field as typed array
    Assert root object is an array of objects
    <ITEM> org.assertj.core.api.ListAssert<ITEM>
    asArray(Class<ITEM> itemClass)
    Assert root object is an array of a single type
    static JsonAssert
    Assert JSON on any object.
    static JsonAssert
    Assert JSON as a String
    field(String fieldName)
    Get field or property by name
    firstField(String fieldName)
    Get the first field (or property) of a JSON object
    lastField(String fieldName)
    Get the last field (or property) of a JSON object
    nthField(String fieldName, int index)
    Get the nth field (or property) of a JSON object
    path(String... fields)
    Find a field using a path

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

    areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, hasToString, inBinary, inHexadecimal, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingRecursiveAssertion, usingRecursiveAssertion, 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, as, describedAs, describedAs
  • Constructor Details

    • JsonAssert

      protected JsonAssert(String json)
      Instantiates a new Json assert.
      Parameters:
      json - the json as a string
  • Method Details

    • assertThat

      public static JsonAssert assertThat(String json)
      Assert JSON as a String
      Parameters:
      json - the json to assert on
      Returns:
      the json assert
    • assertThat

      public static JsonAssert assertThat(Object object)
      Assert JSON on any object. Uses toString() to convert to a string
      Parameters:
      object - the object
      Returns:
      the json assert
    • asArray

      public JsonArrayAssert<?> asArray()
      Assert root object is an array of objects
      Returns:
      the json array assert
      Throws:
      AssertionError - if field cannot be converted to Array
    • asArray

      public <ITEM> org.assertj.core.api.ListAssert<ITEM> asArray(Class<ITEM> itemClass)
      Assert root object is an array of a single type
      Type Parameters:
      ITEM - the item type
      Parameters:
      itemClass - the item class
      Returns:
      the list assert
      Throws:
      AssertionError - if field cannot be converted to Array
    • firstField

      public JsonValueAssert<?> firstField(String fieldName)
      Get the first field (or property) of a JSON object
      Parameters:
      fieldName - the field or property name
      Returns:
      the json value assert
      Throws:
      AssertionError - if field not found
    • lastField

      public JsonValueAssert<?> lastField(String fieldName)
      Get the last field (or property) of a JSON object
      Parameters:
      fieldName - the field or property name
      Returns:
      the json value assert
      Throws:
      AssertionError - if field not found
    • nthField

      public JsonValueAssert<?> nthField(String fieldName, int index)
      Get the nth field (or property) of a JSON object
      Parameters:
      fieldName - the field or property name
      index - the zero based index
      Returns:
      the json value assert
      Throws:
      AssertionError - if field not found
    • field

      public JsonValueAssert<?> field(String fieldName)
      Get field or property by name
      Parameters:
      fieldName - the field or property name
      Returns:
      the json value assert
      Throws:
      AssertionError - if field not found
    • array

      public JsonArrayAssert<?> array(String fieldName)
      Get field as array
      Parameters:
      fieldName - the field name
      Returns:
      the json array assert
      Throws:
      AssertionError - if field is not found or is not an Array
    • array

      public <ITEM> org.assertj.core.api.ListAssert<ITEM> array(String fieldName, Class<ITEM> itemClass)
      Get field as typed array
      Type Parameters:
      ITEM - the type parameter
      Parameters:
      fieldName - the field name
      itemClass - the item class
      Returns:
      the list assert
      Throws:
      AssertionError - if field not found, the field is not an array or the array types cannot be converted
    • path

      public JsonValueAssert<?> path(String... fields)
      Find a field using a path
      Parameters:
      fields - the path segments
      Returns:
      the json value assert
      Throws:
      AssertionError - if path not found