-
- 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.
-
-
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. -
-
Method Detail
-
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 returnsnull
.- Parameters:
property
- The name of the property of this JSON object to converttype
- 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 returnsnull
.- Parameters:
property
- The name of the property of this JSON object to converttype
- 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 returnsnull
.- Parameters:
property
- The name of the property of this JSON object to converttype
- The Class object associated to the<T>
type
-
-
-
-