Class JsonElementValidatorItem<T>

java.lang.Object
org.citrusframework.validation.json.JsonElementValidatorItem<T>
Type Parameters:
T - the type of the actual and expected json

public class JsonElementValidatorItem<T> extends Object
Wraps all needed data to validate an actual json with an expected json-template.
See Also:
  • Field Details

    • actual

      public final T actual
    • expected

      public final T expected
  • Constructor Details

    • JsonElementValidatorItem

      public JsonElementValidatorItem(int index, T actual, T expected)
      For array-items.
      Parameters:
      index - of the item in the parent-element
    • JsonElementValidatorItem

      public JsonElementValidatorItem(String name, T actual, T expected)
      For object-items.
      Parameters:
      name - /key of the json value in the parent-element
  • Method Details

    • parseJson

      public static JsonElementValidatorItem<Object> parseJson(int permissiveMode, String actualJson, String expectedJson)
      Parses and wraps the given json's.
      Parameters:
      permissiveMode - see JSONParser#MODE_* or JSONParser.DEFAULT_PERMISSIVE_MODE
      actualJson - as string
      expectedJson - as string
      Returns:
      the two json's wrapped in a JsonElementValidatorItem<Object>
    • actualAsStringOrNull

      public String actualAsStringOrNull()
      Returns:
      actual as string or null
    • expectedAsStringOrNull

      public String expectedAsStringOrNull()
      Returns:
      expected as string or null
    • ensureType

      public <O> JsonElementValidatorItem<O> ensureType(Class<O> type)
      Parameters:
      type - to cast the values to
      Returns:
      {@link this} as JsonElementValidatorItem<O>
      Throws:
      org.citrusframework.exceptions.ValidationException - if either expected or expected is not of the given type
    • parent

      Set the parent of this json-element.
    • getJsonPath

      public String getJsonPath()
      The json path as string from the root to this item, i.e. $['books'][1]['name']
    • getName

      public String getName()
      The identifier of a json element
      • null on root
      • name for an entry in a json map
      • index in square brackets for an item in a json array, i.e. "[2]"
    • getRoot

      public JsonElementValidatorItem<?> getRoot()
    • isPathIgnoredBy

      public boolean isPathIgnoredBy(String jsonPathExpression)
    • isPathIgnoredBy

      public static boolean isPathIgnoredBy(String jsonPathExpression, String currentPath, Object json)
    • child

      public JsonElementValidatorItem<Object> child(int expectedIndex, Object other)