Class JSONUtils

    • Method Detail

      • parseJSON

        public static Object parseJSON​(String s)
                                throws ParseException
        Parses a JSON value.
        Parameters:
        s - The JSON string to parse. Must not be null.
        Returns:
        The JSON value.
        Throws:
        ParseException - If the string cannot be parsed to a JSON value.
      • parseJSONKeepingOrder

        public static Object parseJSONKeepingOrder​(String s)
                                            throws ParseException
        Parses a JSON value while keeping the order of JSON object members.
        Parameters:
        s - The JSON string to parse. Must not be null.
        Returns:
        The JSON value.
        Throws:
        ParseException - If the string cannot be parsed to a JSON value.
      • to

        public static <T> T to​(Object o,
                               Class<T> clazz)
                        throws ParseException
        Casts an object.
        Parameters:
        o - The object. Must not be null.
        clazz - The expected class of the object. Must not be null.
        Returns:
        The cast object.
        Throws:
        ParseException - If the object is not of the expected type.
      • toBoolean

        public static boolean toBoolean​(Object o)
                                 throws ParseException
        Casts an object to a boolean.
        Parameters:
        o - The object. Must not be null.
        Returns:
        The boolean value.
        Throws:
        ParseException - If the object is not of the expected type.
      • toNumber

        public static Number toNumber​(Object o)
                               throws ParseException
        Casts an object to a number.
        Parameters:
        o - The object. Must not be null.
        Returns:
        The number.
        Throws:
        ParseException - If the object is not of the expected type.
      • toString

        public static String toString​(Object o)
                               throws ParseException
        Casts an object to a string.
        Parameters:
        o - The object. Must not be null.
        Returns:
        The string.
        Throws:
        ParseException - If the object is not of the expected type.
      • toList

        public static List<?> toList​(Object o)
                              throws ParseException
        Casts an object to a list.
        Parameters:
        o - The object. Must not be null.
        Returns:
        The list.
        Throws:
        ParseException - If the object is not of the expected type.
      • toStringList

        public static List<StringtoStringList​(Object o)
                                         throws ParseException
        Casts an object to a list then returns a string list copy of it casting each item to a string.
        Parameters:
        o - The object. Must not be null.
        Returns:
        The string list.
        Throws:
        ParseException - If the object is not of the expected type.