Class GsonJsonProvider
java.lang.Object
com.jayway.jsonpath.spi.json.AbstractJsonProvider
com.jayway.jsonpath.spi.json.GsonJsonProvider
- All Implemented Interfaces:
JsonProvider
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final com.google.gson.Gsonprivate static final com.google.gson.JsonParserFields inherited from interface JsonProvider
UNDEFINED -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates a provider specific json arrayprivate com.google.gson.JsonElementCreates a provider specific json objectgetArrayIndex(Object obj, int idx) Extracts a value from an arraygetMapValue(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 array or objectparse(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 index, 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 stringprivate com.google.gson.JsonArrayprivate com.google.gson.JsonElementprivate com.google.gson.JsonObjectExtracts a value from a wrapper object.private static NumberMethods inherited from class AbstractJsonProvider
getArrayIndex
-
Field Details
-
parser
private static final com.google.gson.JsonParser parser -
gson
private static final com.google.gson.Gson gson
-
-
Constructor Details
-
GsonJsonProvider
public GsonJsonProvider()
-
-
Method Details
-
unwrap
Description copied from interface:JsonProviderExtracts a value from a wrapper object. For JSON providers that to not wrap values, this will usually be the object itself.- Specified by:
unwrapin interfaceJsonProvider- Overrides:
unwrapin classAbstractJsonProvider- Parameters:
o- a value holder object- Returns:
- the unwrapped value.
-
unwrapNumber
-
parse
Description copied from interface:JsonProviderParse the given json string- Parameters:
json- json string to parse- Returns:
- Object representation of json
- Throws:
InvalidJsonException
-
parse
Description copied from interface:JsonProviderParse the given json string- Parameters:
jsonStream- input stream to parsecharset- charset to use- Returns:
- Object representation of json
- Throws:
InvalidJsonException
-
toJson
Description copied from interface:JsonProviderConvert given json object to a json string- Parameters:
obj- object to transform- Returns:
- json representation of object
-
createArray
Description copied from interface:JsonProviderCreates a provider specific json array- Returns:
- new array
-
createMap
Description copied from interface:JsonProviderCreates a provider specific json object- Returns:
- new object
-
isArray
Description copied from class:AbstractJsonProviderchecks if object is an array- Specified by:
isArrayin interfaceJsonProvider- Overrides:
isArrayin classAbstractJsonProvider- Parameters:
obj- object to check- Returns:
- true if obj is an array
-
getArrayIndex
Description copied from class:AbstractJsonProviderExtracts a value from an array- Specified by:
getArrayIndexin interfaceJsonProvider- Overrides:
getArrayIndexin classAbstractJsonProvider- Parameters:
obj- an arrayidx- index- Returns:
- the entry at the given index
-
setArrayIndex
Description copied from interface:JsonProviderSets a value in an array. If the array is too small, the provider is supposed to enlarge it.- Specified by:
setArrayIndexin interfaceJsonProvider- Overrides:
setArrayIndexin classAbstractJsonProvider- Parameters:
array- an arrayindex- indexnewValue- the new value
-
getMapValue
Description copied from class:AbstractJsonProviderExtracts a value from an map- Specified by:
getMapValuein interfaceJsonProvider- Overrides:
getMapValuein classAbstractJsonProvider- Parameters:
obj- a mapkey- property key- Returns:
- the map entry or
JsonProvider.UNDEFINEDfor missing properties
-
setProperty
Description copied from class:AbstractJsonProviderSets a value in an object- Specified by:
setPropertyin interfaceJsonProvider- Overrides:
setPropertyin classAbstractJsonProvider- Parameters:
obj- an objectkey- a String keyvalue- the value to set
-
removeProperty
Description copied from class:AbstractJsonProviderRemoves a value in an object or array- Specified by:
removePropertyin interfaceJsonProvider- Overrides:
removePropertyin classAbstractJsonProvider- Parameters:
obj- an array or an objectkey- a String key or a numerical index to remove
-
isMap
Description copied from class:AbstractJsonProviderchecks if object is a map (i.e. no array)- Specified by:
isMapin interfaceJsonProvider- Overrides:
isMapin classAbstractJsonProvider- Parameters:
obj- object to check- Returns:
- true if the object is a map
-
getPropertyKeys
Description copied from class:AbstractJsonProviderReturns the keys from the given object- Specified by:
getPropertyKeysin interfaceJsonProvider- Overrides:
getPropertyKeysin classAbstractJsonProvider- Parameters:
obj- an object- Returns:
- the keys for an object
-
length
Description copied from class:AbstractJsonProviderGet the length of an array or object- Specified by:
lengthin interfaceJsonProvider- Overrides:
lengthin classAbstractJsonProvider- Parameters:
obj- an array or an object- Returns:
- the number of entries in the array or object
-
toIterable
Description copied from class:AbstractJsonProviderConverts given array to anIterable- Specified by:
toIterablein interfaceJsonProvider- Overrides:
toIterablein classAbstractJsonProvider- Parameters:
obj- an array- Returns:
- an Iterable that iterates over the entries of an array
-
createJsonElement
-
toJsonArray
-
toJsonObject
-
toJsonElement
-