Class JsonObject
java.lang.Object
de.hybris.platform.integrationservices.util.JsonObject
A helper object for evaluating Json content by utilizing JsonPath expressions.
-
Method Summary
Modifier and TypeMethodDescriptionstatic JsonObjectParses JSON content from the input stream and creates new json objectstatic JsonObjectcreateFrom(String json) Parses JSON content and creates new json objectbooleanChecks whether the specified path exists in this JSON object.booleangetBoolean(String jsonPath) Looks up abooleanvalue in the parsed JSONgetCollection(String jsonPath) Looks up entries in the parsed JSONArraygetCollectionOfObjects(String path) Retrieves a collection of data at the location in this object specified by the path.getFilteredCollection(String jsonPath, com.jayway.jsonpath.Predicate filter) Looks up matching entries in the parsed JSONArrayLooks up a value in the parsed JSON.Looks up a value in the parsed JSONbooleanisEmpty()Evaluates whether this object is empty or not.toString()
-
Method Details
-
createFrom
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
Parses JSON content and creates new json object- Parameters:
json- a string in JSON format- Returns:
- presentation of the parsed content
-
getString
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
jsonPathlocation.
-
getObject
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
jsonPathlocation.
-
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
jsonPathlocation and the predicate.
-
getCollection
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
jsonPathlocation. - Throws:
ClassCastException- when the path points to a non-collection valuecom.jayway.jsonpath.PathNotFoundException- when the path does not exist
-
getCollectionOfObjects
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;
nullmeans the path is invalid or does not exist or the path is pointing to a non-collection element in this json object.
-
getBoolean
Looks up abooleanvalue 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
jsonPathlocation. - See Also:
-
exists
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
-