package com.friday.custody.service.trustService.csc.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Map;

public class JsonUtil {
	private static final ObjectMapper om = new ObjectMapper();

	public static String toJsonString(Object bean) {
		try {
			return om.writeValueAsString(bean);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static <T> T toBean(String jsonString, Class<T> beanClass) {
		try {
			return om.readValue(jsonString, beanClass);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@SuppressWarnings("unchecked")
	public static Map<String, Object> toMap(String jsonString) {
		try {
			return om.readValue(jsonString, Map.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
