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

io.github.mrtimeey.herodomainmodel.core.ObjectConversionUtils Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
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();
      }
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy