Package lumis.util
Class JsonUtil
- java.lang.Object
-
- lumis.util.JsonUtil
-
public class JsonUtil extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description JsonUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
getJSONInnerObject(org.json.JSONObject obj, java.lang.String propertyName, boolean isRequired, java.lang.Class<T> desiredClass)
Returns an inner object of the given JSON as an instance of the given desired class.static <T> java.util.List<T>
getListValues(org.json.JSONObject object, java.lang.String key)
Returns aList
from .static <K,T>
java.util.List<T>getListValues(org.json.JSONObject object, java.lang.String key, java.util.function.Function<K,T> parserItem)
Returns aList
from .static boolean
hasValue(org.json.JSONObject obj, java.lang.String key)
Returns whether the given JSON object has a value for the given key.
-
-
-
Method Detail
-
getJSONInnerObject
public static <T> T getJSONInnerObject(org.json.JSONObject obj, java.lang.String propertyName, boolean isRequired, java.lang.Class<T> desiredClass)
Returns an inner object of the given JSON as an instance of the given desired class.- Parameters:
obj
- the JSON object to get inner object.propertyName
- the property name.isRequired
- indicates whether the object is required.desiredClass
- the object desired class to be returned.- Returns:
- an inner object of the given JSON as an instance of the given desired class.
- Since:
- 11.0.0
-
getListValues
public static <T> java.util.List<T> getListValues(org.json.JSONObject object, java.lang.String key)
Returns aList
from . always stores aJSONArray
insteadList
. So, this method create a newList
, puts all items fromJSONArray
and returns.- Parameters:
object
- the JSON owner.key
- the key property of list.- Returns:
- a
List
from . - Since:
- 12.0.0
-
getListValues
public static <K,T> java.util.List<T> getListValues(org.json.JSONObject object, java.lang.String key, java.util.function.Function<K,T> parserItem)
Returns aList
from . always stores aJSONArray
insteadList
. So, this method create a newList
, puts all items fromJSONArray
and returns.- Parameters:
object
- the JSON owner.key
- the key property of list.parserItem
- the parser to transformer each item before add toList
.- Returns:
- a
List
from . - Since:
- 12.0.0
-
hasValue
public static boolean hasValue(org.json.JSONObject obj, java.lang.String key)
Returns whether the given JSON object has a value for the given key.- Parameters:
obj
- the objectkey
- the desired key- Returns:
- whether the given JSON object has a value for the given key.
- Since:
- 12.0.0
-
-