ml.comet.experiment.impl.utils.JsonUtils Maven / Gradle / Ivy
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