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

ml.comet.experiment.impl.utils.JsonUtils Maven / Gradle / Ivy

There is a newer version: 1.1.14
Show newest version
package ml.comet.experiment.impl.utils;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;
import lombok.experimental.UtilityClass;

/**
 * Collection of utilities to process JSON-to-object mappings.
 */
@UtilityClass
public final class JsonUtils {

    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

    @SneakyThrows
    public String toJson(Object object) {
        return OBJECT_MAPPER.writeValueAsString(object);
    }

    @SneakyThrows
    public  T fromJson(String json, Class clazz) {
        return OBJECT_MAPPER.readValue(json, clazz);
    }

    @SneakyThrows
    public  T fromJson(String json, TypeReference typeReference) {
        return OBJECT_MAPPER.readValue(json, typeReference);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy