Interface JsonProvider

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.Object UNDEFINED  
    • Method Summary

      All Methods Instance Methods Abstract Methods Deprecated Methods 
      Modifier and Type Method Description
      java.lang.Object createArray()
      Creates a provider specific json array
      java.lang.Object createMap()
      Creates a provider specific json object
      java.lang.Object getArrayIndex​(java.lang.Object obj, int idx)
      Extracts a value from an array anw unwraps provider specific data type
      java.lang.Object getArrayIndex​(java.lang.Object obj, int idx, boolean unwrap)
      Deprecated.
      java.lang.Object getMapValue​(java.lang.Object obj, java.lang.String key)
      Extracts a value from an map
      java.util.Collection<java.lang.String> getPropertyKeys​(java.lang.Object obj)
      Returns the keys from the given object
      boolean isArray​(java.lang.Object obj)
      checks if object is an array
      boolean isMap​(java.lang.Object obj)
      checks if object is a map (i.e.
      int length​(java.lang.Object obj)
      Get the length of an json array, json object or a json string
      java.lang.Object parse​(java.io.InputStream jsonStream, java.lang.String charset)
      Parse the given json string
      java.lang.Object parse​(java.lang.String json)
      Parse the given json string
      void removeProperty​(java.lang.Object obj, java.lang.Object key)
      Removes a value in an object or array
      void setArrayIndex​(java.lang.Object array, int idx, java.lang.Object newValue)
      Sets a value in an array.
      void setProperty​(java.lang.Object obj, java.lang.Object key, java.lang.Object value)
      Sets a value in an object
      java.lang.Iterable<?> toIterable​(java.lang.Object obj)
      Converts given array to an Iterable
      java.lang.String toJson​(java.lang.Object obj)
      Convert given json object to a json string
      java.lang.Object unwrap​(java.lang.Object obj)
      Extracts a value from a wrapper object.
    • Field Detail

      • UNDEFINED

        static final java.lang.Object UNDEFINED
    • Method Detail

      • parse

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

        java.lang.Object parse​(java.io.InputStream jsonStream,
                               java.lang.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

        java.lang.String toJson​(java.lang.Object obj)
        Convert given json object to a json string
        Parameters:
        obj - object to transform
        Returns:
        json representation of object
      • createArray

        java.lang.Object createArray()
        Creates a provider specific json array
        Returns:
        new array
      • createMap

        java.lang.Object createMap()
        Creates a provider specific json object
        Returns:
        new object
      • isArray

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

        int length​(java.lang.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

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

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

        java.lang.Object getArrayIndex​(java.lang.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
        java.lang.Object getArrayIndex​(java.lang.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​(java.lang.Object array,
                           int idx,
                           java.lang.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

        java.lang.Object getMapValue​(java.lang.Object obj,
                                     java.lang.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​(java.lang.Object obj,
                         java.lang.Object key,
                         java.lang.Object value)
        Sets a value in an object
        Parameters:
        obj - an object
        key - a String key
        value - the value to set
      • removeProperty

        void removeProperty​(java.lang.Object obj,
                            java.lang.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​(java.lang.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

        java.lang.Object unwrap​(java.lang.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.