Package 

Interface JSONValue

  • All Implemented Interfaces:

    
    public interface JSONValue
    
                        

    This interface provides convenient methods to browse a JSON value (typically returned by the underlying Javascript engine). In particular, these methods support conversion to native Java types (such as String, Number, Boolean) as well as to POJO (Plain Old Java Objects) types.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      abstract String stringify() Gets a string representation of this JSON value.
      abstract Object getValue() Gets the raw Javascript object representing this JSON value.
      abstract Object getProperty(String property) If this JSON value is a JSON object, gets the raw Javascript object representing the value of a given property of this JSON object.
      abstract <T> T getValueAs(Class<T> type) Gets this JSON value as an object of a given type.
      abstract <T> T getPropertyAs(String property, Class<T> type) If this JSON value is a JSON object, gets the value of a given property as an object of a given type.
      abstract <T> List<T> getValueAsListOf(Class<T> type) Gets this JSON value as a list of elements of a given type.
      abstract <T> List<T> getPropertyAsListOf(String property, Class<T> type) If this JSON value is a JSON object, gets the value of a given property as a list of elements of a given type.
      abstract <T> Map<String, T> getValueAsMapOf(Class<T> type) Gets this JSON value as an associative map from String to a given type.
      abstract <T> Map<String, T> getPropertyAsMapOf(String property, Class<T> type) If this JSON value is a JSON object, gets the value of a given property as an associative map from String to a given type.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • stringify

         abstract String stringify()

        Gets a string representation of this JSON value.

      • getValue

         abstract Object getValue()

        Gets the raw Javascript object representing this JSON value.

      • getProperty

         abstract Object getProperty(String property)

        If this JSON value is a JSON object, gets the raw Javascript object representing the value of a given property of this JSON object. If this JSON value is not a JSON object or if this JSON object has no property with the given name, then this method returns null.

        Parameters:
        property - The name of the property to retrieve of this JSON object
      • getValueAs

         abstract <T> T getValueAs(Class<T> type)

        Gets this JSON value as an object of a given type. If the conversion is not possible, this method returns null.

        Parameters:
        type - The Class object associated to the <T> type
      • getPropertyAs

         abstract <T> T getPropertyAs(String property, Class<T> type)

        If this JSON value is a JSON object, gets the value of a given property as an object of a given type. If this JSON value is not a JSON object or if this JSON object has no property with the given name, then this method returns null. If the conversion is not possible, this method returns null.

        Parameters:
        property - The name of the property of this JSON object to convert
        type - The Class object associated to the <T> type
      • getValueAsListOf

         abstract <T> List<T> getValueAsListOf(Class<T> type)

        Gets this JSON value as a list of elements of a given type. If the conversion is not possible (either the JSON value is not a list or one of its elements can't be converted to the given type), this method returns null.

        Parameters:
        type - The Class object associated to the <T> type
      • getPropertyAsListOf

         abstract <T> List<T> getPropertyAsListOf(String property, Class<T> type)

        If this JSON value is a JSON object, gets the value of a given property as a list of elements of a given type. If this JSON value is not a JSON object or if this JSON object has no property with the given name, then this method returns null. If the conversion of the given property is not possible (see getValueAsListOf), this method returns null.

        Parameters:
        property - The name of the property of this JSON object to convert
        type - The Class object associated to the <T> type
      • getValueAsMapOf

         abstract <T> Map<String, T> getValueAsMapOf(Class<T> type)

        Gets this JSON value as an associative map from String to a given type. If the conversion is not possible (either the JSON value is not a map or one of its values can't be converted to the given type), this method returns null.

        Parameters:
        type - The Class object associated to the <T> type
      • getPropertyAsMapOf

         abstract <T> Map<String, T> getPropertyAsMapOf(String property, Class<T> type)

        If this JSON value is a JSON object, gets the value of a given property as an associative map from String to a given type. If this JSON value is not a JSON object or if this JSON object has no property with the given name, then this method returns null. If the conversion of the given property is not possible (see getValueAsMapOf), this method returns null.

        Parameters:
        property - The name of the property of this JSON object to convert
        type - The Class object associated to the <T> type