Package lumis.util

Class JsonUtil


  • public class JsonUtil
    extends Object
    • Constructor Detail

      • JsonUtil

        public JsonUtil()
    • Method Detail

      • getJSONInnerObject

        public static <T> T getJSONInnerObject​(org.json.JSONObject obj,
                                               String propertyName,
                                               boolean isRequired,
                                               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> List<T> getListValues​(org.json.JSONObject object,
                                                String key)
        Returns a List from . always stores a JSONArray instead List. So, this method create a new List, puts all items from JSONArray 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> List<T> getListValues​(org.json.JSONObject object,
                                                        String key,
                                                        java.util.function.Function<K,​T> parserItem)
        Returns a List from . always stores a JSONArray instead List. So, this method create a new List, puts all items from JSONArray and returns.
        Parameters:
        object - the JSON owner.
        key - the key property of list.
        parserItem - the parser to transformer each item before add to List.
        Returns:
        a List from .
        Since:
        12.0.0
      • hasValue

        public static boolean hasValue​(org.json.JSONObject obj,
                                       String key)
        Returns whether the given JSON object has a value for the given key.
        Parameters:
        obj - the object
        key - the desired key
        Returns:
        whether the given JSON object has a value for the given key.
        Since:
        12.0.0