Class JsonObject
- java.lang.Object
-
- de.hybris.platform.integrationservices.util.JsonObject
-
public class JsonObject extends java.lang.ObjectA helper object for evaluating Json content by utilizing JsonPath expressions.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static JsonObjectcreateFrom(java.io.InputStream in)Parses JSON content from the input stream and creates new json objectstatic JsonObjectcreateFrom(java.lang.String json)Parses JSON content and creates new json objectbooleanexists(java.lang.String path)Checks whether the specified path exists in this JSON object.booleangetBoolean(java.lang.String jsonPath)Looks up abooleanvalue in the parsed JSONjava.util.List<java.util.Map<java.lang.String,java.lang.Object>>getCollection(java.lang.String jsonPath)Looks up entries in the parsed JSONArrayjava.util.List<java.lang.Object>getCollectionOfObjects(java.lang.String path)Retrieves a collection of data at the location in this object specified by the path.java.util.List<java.util.Map<java.lang.String,java.lang.Object>>getFilteredCollection(java.lang.String jsonPath, com.jayway.jsonpath.Predicate filter)Looks up matching entries in the parsed JSONArrayjava.lang.ObjectgetObject(java.lang.String jsonPath)Looks up a value in the parsed JSON.java.lang.StringgetString(java.lang.String jsonPath)Looks up a value in the parsed JSONjava.lang.StringtoString()
-
-
-
Method Detail
-
createFrom
public static JsonObject createFrom(java.io.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(java.lang.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 java.lang.String getString(java.lang.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
jsonPathlocation.
-
getObject
public java.lang.Object getObject(java.lang.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
jsonPathlocation.
-
getFilteredCollection
public java.util.List<java.util.Map<java.lang.String,java.lang.Object>> getFilteredCollection(java.lang.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
public java.util.List<java.util.Map<java.lang.String,java.lang.Object>> getCollection(java.lang.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
jsonPathlocation. - Throws:
java.lang.ClassCastException- when the path points to a non-collection valuecom.jayway.jsonpath.PathNotFoundException- when the path does not exist
-
getCollectionOfObjects
public java.util.List<java.lang.Object> getCollectionOfObjects(java.lang.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;
nullmeans 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(java.lang.String jsonPath)
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:
for the rules about how the boolean value is derived
-
exists
public boolean exists(java.lang.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.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-