I have these 3 methods below. I only don't have a clue to make them as one, as they are type of array, list or just an object. These methods just convert a given object to a json string and then convert it to the specified class that was given.
public static List<Object> objectListSerializer(List<Document> documents, Class entity) {
List<Object> entityList;
String json = com.mongodb.util.JSON.serialize(documents);
entityList = (List<Object>) GSON_INSTANCE.fromJson(json, entity);
return entityList;
}
public static Object objectArraySerializer(Object objectArray, Class clazz) {
String jsonString = GSON_INSTANCE.toJson(objectArray);
Object convert[] = (Object[]) GSON_INSTANCE.fromJson(jsonString, clazz);
return convert;
}
public static Object objectSerializer(Object object, Class clazz) {
String jsonString = GSON_INSTANCE.toJson(object);
Object convert = GSON_INSTANCE.fromJson(jsonString, clazz);
return convert;
}