Package org.svetovid.util
Class JsonHelper
java.lang.Object
org.svetovid.util.JsonHelper
Helper class with many useful methods for manipulating JSON compatible
objects.
- Author:
- Ivan Pribela
-
Constructor Summary
ConstructorsConstructorDescriptionJsonHelper(Object object) Constructs a newJsonHelperwrapper for easier manipulation of the given JSON compatible object. -
Method Summary
Modifier and TypeMethodDescriptionIterable<?>asArray()Returns an array value of this object.static Iterable<?>Returns the given object converted to a JSON array value.Returns a boolean value of this object.static BooleanReturns the given object converted to a boolean value.asNumber()Returns a numeric value of this object.static NumberReturns the given object converted to a number value.asObject()Returns an object value of this object.Returns the given object converted to an JSON object value.asString()Returns a string value of this object.static StringReturns the given object converted to a string value.static ObjectReturns the raw object at the specified JSON path resolved on the given object.static Iterable<?>Returns an array value at the specified JSON path resolved on the given object.static BooleangetBoolean(Object object, String path) Returns a boolean value at the specified JSON path resolved on the given object.static NumberReturns a numeric value at the specified JSON path resolved on the given object.Returns an object value at the specified JSON path resolved on the given object.static StringReturns a string value at the specified JSON path resolved on the given object.getType()Returns the JSON type of this object.static JsonTypeReturns the JSON type to which the given object can be converted.
-
Constructor Details
-
JsonHelper
Constructs a newJsonHelperwrapper for easier manipulation of the given JSON compatible object.- Parameters:
object- the object to wrap
-
-
Method Details
-
getType
Returns the JSON type of this object.- Returns:
- the JSON type of this object.
-
asBoolean
Returns a boolean value of this object.- Returns:
- a boolean value of this object.
- Throws:
SvetovidJsonException- if the object cannot be converted.
-
asNumber
Returns a numeric value of this object.- Returns:
- a numeric value of this object.
- Throws:
SvetovidJsonException- if the object cannot be converted.
-
asString
Returns a string value of this object.- Returns:
- a string value of this object.
- Throws:
SvetovidJsonException- if the object cannot be converted.
-
asArray
Returns an array value of this object.- Returns:
- an array value of this object.
- Throws:
SvetovidJsonException- if the object cannot be converted.
-
asObject
Returns an object value of this object.- Returns:
- an object value of this object.
- Throws:
SvetovidJsonException- if the object cannot be converted.
-
getType
Returns the JSON type to which the given object can be converted.- Parameters:
object- the object for which the type is determined- Returns:
- JSON type of the given object.
-
asBoolean
Returns the given object converted to a boolean value.- Parameters:
object- the object to convert- Returns:
- a boolean value of the given object.
- Throws:
SvetovidJsonException- if the object cannot be converted.
-
asNumber
Returns the given object converted to a number value.- Parameters:
object- the object to convert- Returns:
- a number value of the given object.
- Throws:
SvetovidJsonException- if the object cannot be converted.
-
asString
Returns the given object converted to a string value.- Parameters:
object- the object to convert- Returns:
- a string value of the given object.
- Throws:
SvetovidJsonException- if the object cannot be converted.
-
asArray
Returns the given object converted to a JSON array value.- Parameters:
object- the object to convert- Returns:
- an array value of the given object.
- Throws:
SvetovidJsonException- if the object cannot be converted.
-
asObject
Returns the given object converted to an JSON object value.- Parameters:
object- the object to convert- Returns:
- an object value of the given object.
- Throws:
SvetovidJsonException- if the object cannot be converted.
-
getBoolean
Returns a boolean value at the specified JSON path resolved on the given object.- Parameters:
object- the object to apply the path topath- the path to follow- Returns:
- the boolean value extracted from the given object using the given path.
- Throws:
SvetovidJsonException- if the object cannot be converted.
-
getNumber
Returns a numeric value at the specified JSON path resolved on the given object.- Parameters:
object- the object to apply the path topath- the path to follow- Returns:
- the numeric value extracted from the given object using the given path.
- Throws:
SvetovidJsonException- if the object cannot be converted.
-
getString
Returns a string value at the specified JSON path resolved on the given object.- Parameters:
object- the object to apply the path topath- the path to follow- Returns:
- the string value extracted from the given object using the given path.
- Throws:
SvetovidJsonException- if the object cannot be converted.
-
getArray
Returns an array value at the specified JSON path resolved on the given object.- Parameters:
object- the object to apply the path topath- the path to follow- Returns:
- the array value extracted from the given object using the given path.
- Throws:
SvetovidJsonException- if the object cannot be converted.
-
getObject
Returns an object value at the specified JSON path resolved on the given object.- Parameters:
object- the object to apply the path topath- the path to follow- Returns:
- the object value extracted from the given object using the given path.
- Throws:
SvetovidJsonException- if the object cannot be converted.
-
get
Returns the raw object at the specified JSON path resolved on the given object.- Parameters:
object- the object to apply the path topath- the path to follow- Returns:
- the raw object extracted from the given object using the given path.
- Throws:
SvetovidFormatException- if there was an error parsing the path.SvetovidJsonException- if the array or object along the path cannot be converted.
-