
com.ithit.webdav.integration.utils.SerializationUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jakarta-integration Show documentation
Show all versions of jakarta-integration Show documentation
IT Hit WebDAV integration for new Jakarta Java servlet containers
package com.ithit.webdav.integration.utils;
import com.google.gson.Gson;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Utility class to perform serialization of objects.
*/
public final class SerializationUtils {
private SerializationUtils() {
}
/**
* Serializes object to JSON string.
*
* @param object Object to serialize.
* @return String in JSON format
*/
public static String serialize(T object) {
Gson gson = new Gson();
return gson.toJson(object);
}
/**
* Deserialize JSON string to object list.
*
* @param clazz Type of objects in the list to deserialize.
* @param json JSON string to deserialize.
* @return List of objects.
*/
@SuppressWarnings("unchecked")
public static List deserializeList(final Class clazz, final String json) {
T[] array = (T[]) java.lang.reflect.Array.newInstance(clazz, 1);
array = new Gson().fromJson(json, (Type) array.getClass());
if (array == null) {
return new ArrayList<>();
}
return new ArrayList<>(Arrays.asList(array));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy