java.lang.Object
de.hybris.platform.integrationservices.util.JsonObject

public class JsonObject extends Object
A helper object for evaluating Json content by utilizing JsonPath expressions.
  • Method Details

    • createFrom

      public static JsonObject createFrom(InputStream in)
      Parses JSON content from the input stream and creates new json object
      Parameters:
      in - an input stream containing JSON
      Returns:
      presentation of the parsed content
    • createFrom

      public static JsonObject createFrom(String json)
      Parses JSON content and creates new json object
      Parameters:
      json - a string in JSON format
      Returns:
      presentation of the parsed content
    • getString

      public String getString(String jsonPath)
      Looks up a value in the parsed JSON
      Parameters:
      jsonPath - a JSON path, e.g. product.code, pointing to the element whose value needs to be retrieved.
      Returns:
      value of the element matching the jsonPath location.
    • getObject

      public Object getObject(String jsonPath)
      Looks up a value in the parsed JSON. This method is convenient when it's not known what type the path should return.
      Parameters:
      jsonPath - a JSON path, e.g. product.code, pointing to the element whose value needs to be retrieved.
      Returns:
      value of the element matching the jsonPath location.
    • getFilteredCollection

      public List<Map<String,Object>> getFilteredCollection(String jsonPath, com.jayway.jsonpath.Predicate filter)
      Looks up matching entries in the parsed JSONArray
      Parameters:
      jsonPath - a JSON path, e.g. product.code, pointing to the element whose value needs to be retrieved.
      filter - Predicate used for filtering matching entry results
      Returns:
      List of entries matching the jsonPath location and the predicate.
    • getCollection

      public List<Map<String,Object>> getCollection(String jsonPath)
      Looks up entries in the parsed JSONArray
      Parameters:
      jsonPath - a JSON path, e.g. product.code, pointing to the element whose value needs to be retrieved.
      Returns:
      List of entries matching the jsonPath location.
      Throws:
      ClassCastException - when the path points to a non-collection value
      com.jayway.jsonpath.PathNotFoundException - when the path does not exist
    • getCollectionOfObjects

      public List<Object> getCollectionOfObjects(String path)
      Retrieves a collection of data at the location in this object specified by the path.
      Parameters:
      path - path expression to select a collection of objects.
      Returns:
      a collection of data selected by the path expression; null means the path is invalid or does not exist or the path is pointing to a non-collection element in this json object.
    • getBoolean

      public boolean getBoolean(String jsonPath)
      Looks up a boolean value in the parsed JSON
      Parameters:
      jsonPath - a JSON path, e.g. catalog.active, pointing to the element whose value needs to be retrieved.
      Returns:
      value of the element matching the jsonPath location.
      See Also:
    • exists

      public boolean exists(String path)
      Checks whether the specified path exists in this JSON object.
      Parameters:
      path - a path to check.
      Returns:
      true, if the path exists in this JSON object and contains non-null value or non-empty value in case when the path resolves to an array; false, otherwise.
    • isEmpty

      public boolean isEmpty()
      Evaluates whether this object is empty or not.
      Returns:
      true, if this object represents an empty JSON, e.g. "{}"; false, if the object contains at least one nested element.
    • toString

      public String toString()
      Overrides:
      toString in class Object