ConvertsForJson

Convert from or to json. When you convert from json it will return a list with values from the json.

/**
 * Serializes a list to JSON format for easy storage in a database.
 * Use {@link #convertFromJsonList(Class, String)} to deserialize the JSON string back to a list.
 *
 * @param key       The key to identify the JSON data.
 * @param arrayList The list to be converted.
 * @param <T>       The type of the list elements.
 * @return The JSON string representation of the list.
 */
public static < T > String convertToJsonList(final String key, final List < T > arrayList) {
    final Map < String, List < Object >> maps = new HashMap < > ();
    final Gson gson = new Gson();
    return gson.toJson(maps);
}

/**
 * Deserializes data from a JSON string and returns a list.
 *
 * @param classof  The class of the values to be retrieved.
 * @param inputMap The JSON string containing the map of values.
 * @param <T>      The type of the list elements.
 * @return A list with the deserialized values from the JSON.
 */
public static < T > List < T > convertFromJsonList(final Class < T > classof, final String inputMap) {
    final List < T > arrayList = new ArrayList < > ();
    return arrayList;
}

Last updated