Interface JsonProvider

All Known Implementing Classes:
AbstractJsonProvider, GsonJsonProvider, JacksonJsonNodeJsonProvider, JacksonJsonProvider, JsonSmartJsonProvider

public interface JsonProvider
  • Field Details

    • UNDEFINED

      static final Object UNDEFINED
  • Method Details

    • parse

      Object parse(String json) throws InvalidJsonException
      Parse the given json string
      Parameters:
      json - json string to parse
      Returns:
      Object representation of json
      Throws:
      InvalidJsonException
    • parse

      Object parse(InputStream jsonStream, String charset) throws InvalidJsonException
      Parse the given json string
      Parameters:
      jsonStream - input stream to parse
      charset - charset to use
      Returns:
      Object representation of json
      Throws:
      InvalidJsonException
    • toJson

      String toJson(Object obj)
      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

      boolean isArray(Object obj)
      checks if object is an array
      Parameters:
      obj - object to check
      Returns:
      true if obj is an array
    • length

      int length(Object obj)
      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

      Iterable<?> toIterable(Object obj)
      Converts given array to an Iterable
      Parameters:
      obj - an array
      Returns:
      an Iterable that iterates over the entries of an array
    • getPropertyKeys

      Collection<String> getPropertyKeys(Object obj)
      Returns the keys from the given object
      Parameters:
      obj - an object
      Returns:
      the keys for an object
    • getArrayIndex

      Object getArrayIndex(Object obj, int idx)
      Extracts a value from an array anw unwraps provider specific data type
      Parameters:
      obj - an array
      idx - index
      Returns:
      the entry at the given index
    • getArrayIndex

      @Deprecated Object getArrayIndex(Object obj, int idx, boolean unwrap)
      Deprecated.
      Extracts a value from an array
      Parameters:
      obj - an array
      idx - index
      unwrap - should provider specific data type be unwrapped
      Returns:
      the entry at the given index
    • setArrayIndex

      void setArrayIndex(Object array, int idx, Object newValue)
      Sets a value in an array. If the array is too small, the provider is supposed to enlarge it.
      Parameters:
      array - an array
      idx - index
      newValue - the new value
    • getMapValue

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

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

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

      boolean isMap(Object obj)
      checks if object is a map (i.e. no array)
      Parameters:
      obj - object to check
      Returns:
      true if the object is a map
    • unwrap

      Object unwrap(Object obj)
      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.