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

com.arextest.schedule.common.JsonUtils Maven / Gradle / Ivy

There is a newer version: 1.2.20
Show newest version
package com.arextest.schedule.common;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * @author wildeslam.
 * @create 2023/11/23 16:20
 */
@Slf4j
public class JsonUtils {
  private static final ObjectMapper objectMapper = new ObjectMapper();

  public static   T byteToObject(byte[] bytes, Class tClass) {
    try {
      return objectMapper.readValue(bytes, tClass);
    } catch (IOException e) {
      LOGGER.error("byteToObject error:{}", e.getMessage(), e);
    }
    return null;
  }

  public static String objectToJsonString(Object value) {
    try {
      return objectMapper.writeValueAsString(value);
    } catch (IOException e) {
      LOGGER.error("byteToObject error:{}", e.getMessage(), e);
    }
    return StringUtils.EMPTY;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy