io.soffa.foundation.commons.YamlUtil Maven / Gradle / Ivy
package io.soffa.foundation.commons;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import lombok.SneakyThrows;
import java.io.File;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
public final class YamlUtil {
private static final ObjectMapper MAPPER = ObjectFactory.create(new YAMLMapper(), false);
// private static final ObjectMapper MAPPER_FULL_ACCESS = ObjectFactory.create(new YAMLMapper(), true);
private YamlUtil() {
}
@SneakyThrows
public static T deserialize(String yamlString, Class type) {
return ObjectFactory.deserialize(MAPPER, yamlString, type);
}
public static T convert(Object input, Class type) {
return ObjectFactory.convert(MAPPER, input, type);
}
public static String serialize(Object src) {
return ObjectFactory.serialize(MAPPER, src);
}
public static void serializeToFile(Object content, File file) {
ObjectFactory.serializeToFile(MAPPER, content, file);
}
public static Map deserializeMap(String input) {
return ObjectFactory.deserializeMap(MAPPER, input);
}
public static Map deserializeMap(InputStream input) {
return ObjectFactory.deserializeMap(MAPPER, input);
}
public static Map deserializeMap(InputStream input, Class type) {
return ObjectFactory.deserializeMap(MAPPER, input, type);
}
public static Map deserializeMap(String input, Class type) {
return ObjectFactory.deserializeMap(MAPPER, input, type);
}
public static T deserializeParametricType(String input, Class> rawType, Class>... parameterClasses) {
return ObjectFactory.deserializeParametricType(MAPPER, input, rawType, parameterClasses);
}
public static List deserializeList(String input, Class type) {
return ObjectFactory.deserializeList(MAPPER, input, type);
}
public static List deserializeList(InputStream input, Class type) {
return ObjectFactory.deserializeList(MAPPER, input, type);
}
public static Map toMap(Object input) {
return toMap(input, Object.class);
}
public static Map toMap(Object input, Class valueClass) {
return ObjectFactory.toMap(MAPPER, input, valueClass);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy