io.github.mrtimeey.herodomainmodel.core.ObjectConversionUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of object-finder Show documentation
Show all versions of object-finder Show documentation
Library for finding objects in complex data structures
package io.github.mrtimeey.herodomainmodel.core;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Optional;
final class ObjectConversionUtils {
private static final ObjectMapper om = new ObjectMapper().enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
private ObjectConversionUtils() {
throw new IllegalStateException("Do not instantiate this class");
}
static Optional toObject(String objString, TypeReference typeReference) {
try {
T value = om.readValue(objString, typeReference);
return Optional.of(value);
} catch (Exception e) {
return Optional.empty();
}
}
}