Package lumis.util

Class 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 a List 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 a List 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.
      • Methods inherited from class java.lang.Object

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

      • JsonUtil

        public JsonUtil()
    • 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 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> java.util.List<T> getListValues​(org.json.JSONObject object,
                                                                  java.lang.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,
                                       java.lang.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