Class JSONUtils

  • All Implemented Interfaces:

    
    public final class JSONUtils
    
                        

    Utility class for JSON objects.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      static boolean isNullOrEmpty(@Nullable() JSONObject jsonObject) Checks if the provided JSONObject is null or it has no element
      static boolean isNullOrEmpty(@Nullable() JSONArray jsonArray) Checks if the provided JSONArray is null or it has no element
      static Map<String, Object> toMap(@Nullable() JSONObject jsonObject) Converts contents of a JSONObject into a Map<String, Object>
      static List<Object> toList(@Nullable() JSONArray jsonArray) Converts contents of a JSONObject into a List<Object>
      • Methods inherited from class java.lang.Object

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

    • Method Detail

      • isNullOrEmpty

         static boolean isNullOrEmpty(@Nullable() JSONObject jsonObject)

        Checks if the provided JSONObject is null or it has no element

        Parameters:
        jsonObject - the JSONObject to be verified
        Returns:

        true if null or empty, false otherwise

      • isNullOrEmpty

         static boolean isNullOrEmpty(@Nullable() JSONArray jsonArray)

        Checks if the provided JSONArray is null or it has no element

        Parameters:
        jsonArray - the JSONArray to be verified
        Returns:

        true if null or empty, false otherwise

      • toMap

        @Nullable() static Map<String, Object> toMap(@Nullable() JSONObject jsonObject)

        Converts contents of a JSONObject into a Map<String, Object>

        Parameters:
        jsonObject - the JSONObject that is to be converted to Map
        Returns:

        Map<String, Object> obtained after converting the JSONObject

      • toList

        @Nullable() static List<Object> toList(@Nullable() JSONArray jsonArray)

        Converts contents of a JSONObject into a List<Object>

        Parameters:
        jsonArray - the JSONArray that is to be converted to a List
        Returns:

        List<Object> obtained after converting the JSONObject