All Downloads are FREE. Search and download functionalities are using the official Maven repository.

co.com.bancolombia.secretsmanager.commons.utils.GsonUtils Maven / Gradle / Ivy

There is a newer version: 4.4.24
Show newest version
package co.com.bancolombia.secretsmanager.commons.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
 * Singleton - Gson
 *
 * @author [email protected] IAS
 * @version 1.0.0
 * @since JDK 1.8
 */
public class GsonUtils {

    private final Gson gson;

    private GsonUtils() {
        gson = new GsonBuilder()
                .create();
    }

    public static GsonUtils getInstance() {
        return GsonUtilsHolder.INSTANCE;
    }

    private static class GsonUtilsHolder {
        private static final GsonUtils INSTANCE = new GsonUtils();
    }

    /**
     * @param data  JSON string
     * @param model Entity to convert
     * @param    object
     * @return T object
     */
    public  T stringToModel(String data, Class model) {
        return gson.fromJson(data, model);
    }

    public String modelToString(Object model) {
        return gson.toJson(model);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy