Package com.jayway.jsonpath.spi.json
Interface JsonProvider
- All Known Implementing Classes:
AbstractJsonProvider,GsonJsonProvider,JacksonJsonNodeJsonProvider,JacksonJsonProvider,JsonSmartJsonProvider
public interface JsonProvider
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionCreates a provider specific json arrayCreates a provider specific json objectgetArrayIndex(Object obj, int idx) Extracts a value from an array anw unwraps provider specific data typegetArrayIndex(Object obj, int idx, boolean unwrap) Deprecated.getMapValue(Object obj, String key) Extracts a value from an mapgetPropertyKeys(Object obj) Returns the keys from the given objectbooleanchecks if object is an arraybooleanchecks if object is a map (i.e.intGet the length of an json array, json object or a json stringparse(InputStream jsonStream, String charset) Parse the given json stringParse the given json stringvoidremoveProperty(Object obj, Object key) Removes a value in an object or arrayvoidsetArrayIndex(Object array, int idx, Object newValue) Sets a value in an array.voidsetProperty(Object obj, Object key, Object value) Sets a value in an objectIterable<?> toIterable(Object obj) Converts given array to anIterableConvert given json object to a json stringExtracts a value from a wrapper object.
-
Field Details
-
UNDEFINED
-
-
Method Details
-
parse
Parse the given json string- Parameters:
json- json string to parse- Returns:
- Object representation of json
- Throws:
InvalidJsonException
-
parse
Parse the given json string- Parameters:
jsonStream- input stream to parsecharset- charset to use- Returns:
- Object representation of json
- Throws:
InvalidJsonException
-
toJson
Convert given json object to a json string- Parameters:
obj- object to transform- Returns:
- json representation of object
-
createArray
Object createArray()Creates a provider specific json array- Returns:
- new array
-
createMap
Object createMap()Creates a provider specific json object- Returns:
- new object
-
isArray
checks if object is an array- Parameters:
obj- object to check- Returns:
- true if obj is an array
-
length
Get the length of an json array, json object or a json string- Parameters:
obj- an array or object or a string- Returns:
- the number of entries in the array or object
-
toIterable
Converts given array to anIterable- Parameters:
obj- an array- Returns:
- an Iterable that iterates over the entries of an array
-
getPropertyKeys
Returns the keys from the given object- Parameters:
obj- an object- Returns:
- the keys for an object
-
getArrayIndex
Extracts a value from an array anw unwraps provider specific data type- Parameters:
obj- an arrayidx- index- Returns:
- the entry at the given index
-
getArrayIndex
Deprecated.Extracts a value from an array- Parameters:
obj- an arrayidx- indexunwrap- should provider specific data type be unwrapped- Returns:
- the entry at the given index
-
setArrayIndex
Sets a value in an array. If the array is too small, the provider is supposed to enlarge it.- Parameters:
array- an arrayidx- indexnewValue- the new value
-
getMapValue
Extracts a value from an map- Parameters:
obj- a mapkey- property key- Returns:
- the map entry or
UNDEFINEDfor missing properties
-
setProperty
Sets a value in an object- Parameters:
obj- an objectkey- a String keyvalue- the value to set
-
removeProperty
Removes a value in an object or array- Parameters:
obj- an array or an objectkey- a String key or a numerical index to remove
-
isMap
checks if object is a map (i.e. no array)- Parameters:
obj- object to check- Returns:
- true if the object is a map
-
unwrap
Extracts a value from a wrapper object. For JSON providers that to not wrap values, this will usually be the object itself.- Parameters:
obj- a value holder object- Returns:
- the unwrapped value.
-