package com.elephant.framework.galaxy.aroad.util;

import org.codehaus.jackson.map.ObjectMapper;

import java.util.List;

/**
 * @program:
 * @description: 序列化工具类
 * @author: songwenjie
 * @create: 2019-04-23 17:26
 **/
public class JsonUtil {
    static ObjectMapper objectMapper = new ObjectMapper();

    public static String toJson (Object obj) throws Exception{
        String json = objectMapper.writeValueAsString(obj);
        return json;
    }

    public static Object toObject (String json) throws Exception{
        Object obj = objectMapper.readValue(json, Object.class);
        return obj;
    }

    public static List toList (String json) throws Exception{
        List list = objectMapper.readValue(json, List.class);
        return list;
    }
}
