Class Jackie


  • public class Jackie
    extends Object
    Main Jackie class, that provides converting of objects to JSON as String and JSON String to objects.
    Author:
    michalt
    • Constructor Detail

      • Jackie

        public Jackie()
    • Method Detail

      • toJson

        public <T> String toJson​(T object)
        Converts single object into JSON as String.
        Type Parameters:
        T - the generic type
        Parameters:
        object - the object
        Returns:
        the string
      • fromJson

        public <T> T fromJson​(String json,
                              Class<T> clazz)
        Converts single object or array from JSON to instance of clazz.
        If clazz is going to be a List, @see Jackie#fromJson(String, Class, Class) to define the Type of list.
        If clazz is going to be Map, @see Jackie#fromJson(String, Class, Class, Class) to define key and value classes, if you want to avoid to be used String and Object.
        Type Parameters:
        T - the generic type
        Parameters:
        json - the json
        clazz - the clazz
        Returns:
        the t
      • fromJson

        public <T> T fromJson​(String json,
                              Class<T> clazz,
                              Class<?> subClazz)
        Converts List or array from JSON. If it converts list, subClazz needs to be defined as generic type of List.
        Type Parameters:
        T - the generic type
        Parameters:
        json - the json
        clazz - the clazz
        subClazz - the sub clazz
        Returns:
        the t
      • fromJson

        public <T> T fromJson​(String json,
                              Class<T> clazz,
                              Class<?> keyClazz,
                              Class<?> valueClazz)
        Converts Map from JSON. It needs to have defined keyClazz as class of Key attribute and valueClazz as class of Value attribute.
        Type Parameters:
        T - the generic type
        Parameters:
        json - the json
        clazz - the clazz
        keyClazz - the key clazz
        valueClazz - the value clazz
        Returns:
        the t