Class AbstractJsonProvider

java.lang.Object
com.jayway.jsonpath.spi.json.AbstractJsonProvider
All Implemented Interfaces:
JsonProvider
Direct Known Subclasses:
GsonJsonProvider, JacksonJsonNodeJsonProvider, JacksonJsonProvider, JsonSmartJsonProvider

public abstract class AbstractJsonProvider extends Object implements JsonProvider
  • Constructor Details

    • AbstractJsonProvider

      public AbstractJsonProvider()
  • Method Details

    • isArray

      public boolean isArray(Object obj)
      checks if object is an array
      Specified by:
      isArray in interface JsonProvider
      Parameters:
      obj - object to check
      Returns:
      true if obj is an array
    • getArrayIndex

      public Object getArrayIndex(Object obj, int idx)
      Extracts a value from an array
      Specified by:
      getArrayIndex in interface JsonProvider
      Parameters:
      obj - an array
      idx - index
      Returns:
      the entry at the given index
    • getArrayIndex

      public final Object getArrayIndex(Object obj, int idx, boolean unwrap)
      Description copied from interface: JsonProvider
      Extracts a value from an array
      Specified by:
      getArrayIndex in interface JsonProvider
      Parameters:
      obj - an array
      idx - index
      unwrap - should provider specific data type be unwrapped
      Returns:
      the entry at the given index
    • setArrayIndex

      public void setArrayIndex(Object array, int index, Object newValue)
      Description copied from interface: JsonProvider
      Sets a value in an array. If the array is too small, the provider is supposed to enlarge it.
      Specified by:
      setArrayIndex in interface JsonProvider
      Parameters:
      array - an array
      index - index
      newValue - the new value
    • getMapValue

      public Object getMapValue(Object obj, String key)
      Extracts a value from an map
      Specified by:
      getMapValue in interface JsonProvider
      Parameters:
      obj - a map
      key - property key
      Returns:
      the map entry or JsonProvider.UNDEFINED for missing properties
    • setProperty

      public void setProperty(Object obj, Object key, Object value)
      Sets a value in an object
      Specified by:
      setProperty in interface JsonProvider
      Parameters:
      obj - an object
      key - a String key
      value - the value to set
    • removeProperty

      public void removeProperty(Object obj, Object key)
      Removes a value in an object or array
      Specified by:
      removeProperty in interface JsonProvider
      Parameters:
      obj - an array or an object
      key - a String key or a numerical index to remove
    • isMap

      public boolean isMap(Object obj)
      checks if object is a map (i.e. no array)
      Specified by:
      isMap in interface JsonProvider
      Parameters:
      obj - object to check
      Returns:
      true if the object is a map
    • getPropertyKeys

      public Collection<String> getPropertyKeys(Object obj)
      Returns the keys from the given object
      Specified by:
      getPropertyKeys in interface JsonProvider
      Parameters:
      obj - an object
      Returns:
      the keys for an object
    • length

      public int length(Object obj)
      Get the length of an array or object
      Specified by:
      length in interface JsonProvider
      Parameters:
      obj - an array or an object
      Returns:
      the number of entries in the array or object
    • toIterable

      public Iterable<? extends Object> toIterable(Object obj)
      Converts given array to an Iterable
      Specified by:
      toIterable in interface JsonProvider
      Parameters:
      obj - an array
      Returns:
      an Iterable that iterates over the entries of an array
    • unwrap

      public Object unwrap(Object obj)
      Description copied from interface: JsonProvider
      Extracts a value from a wrapper object. For JSON providers that to not wrap values, this will usually be the object itself.
      Specified by:
      unwrap in interface JsonProvider
      Parameters:
      obj - a value holder object
      Returns:
      the unwrapped value.