content: package dev.agitrubard.report.util;
  
  import com.fasterxml.jackson.core.JsonProcessingException;
  import com.fasterxml.jackson.core.type.TypeReference;
  import com.fasterxml.jackson.databind.ObjectMapper;
  import lombok.AccessLevel;
  import lombok.NoArgsConstructor;
  import lombok.extern.slf4j.Slf4j;
  import org.apache.commons.lang3.StringUtils;
  import org.mapstruct.Named;
  
  import java.util.Map;
  
  @Slf4j
  @NoArgsConstructor(access = AccessLevel.PRIVATE)
  public final class JsonUtil {
  
      private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
  
      @Named("MapUtil.toMap")
      public static Map<Object, Object> toMap(String json) {
  
          if (StringUtils.isBlank(json)) {
              return null;
          }
  
          try {
              return OBJECT_MAPPER.readValue(json, new TypeReference<>() {
              });
          } catch (JsonProcessingException exception) {
              log.warn("Failed to parse JSON string to map: {}, message: {}", json, exception.getMessage());
              return null;
          }
      }
  
      public static String toString(Object object) {
  
          try {
              return OBJECT_MAPPER.writeValueAsString(object);
          } catch (JsonProcessingException exception) {
              log.warn("Failed to parse object to JSON string: {}, message: {}", object, exception.getMessage());
              return null;
          }
  
      }
  
  }
  