package cc.mrbird.febs.pay.util; 
 | 
  
 | 
import com.alibaba.fastjson.JSON; 
 | 
import com.alibaba.fastjson.JSONArray; 
 | 
import com.alibaba.fastjson.PropertyNamingStrategy; 
 | 
import com.alibaba.fastjson.serializer.SerializeConfig; 
 | 
  
 | 
import java.lang.reflect.Type; 
 | 
import java.util.List; 
 | 
  
 | 
/** 
 | 
 * JSON转换工具类 
 | 
 * @author chenyf 
 | 
 * @date 2018-12-15 
 | 
 */ 
 | 
public class JsonUtil { 
 | 
  
 | 
    /** 
 | 
     * 将一个对像转成一个json字符串 
 | 
     */ 
 | 
    public static final String toString(Object obj) { 
 | 
        return JSON.toJSONString(obj); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 把json字符串转换成指定Class的对象 
 | 
     * @param text 
 | 
     * @param clazz 
 | 
     * @param <T> 
 | 
     * @return 
 | 
     */ 
 | 
    public static <T> T toBean(String text, Class<T> clazz) { 
 | 
        return JSON.parseObject(text, clazz); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 把json字节转换成指定Class的对象 
 | 
     * @param text 
 | 
     * @param clazz 
 | 
     * @param <T> 
 | 
     * @return 
 | 
     */ 
 | 
    public static <T> T toBean(byte[] text, Class<T> clazz) { 
 | 
        return JSON.parseObject(text, clazz); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 把json字符串转换成指定类型的对象 
 | 
     * @param text 
 | 
     * @param type 
 | 
     * @param <T> 
 | 
     * @return 
 | 
     */ 
 | 
    public static <T> T toBean(String text, Type type) { 
 | 
        return JSON.parseObject(text, type); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 把json字符串转换为指定Class的List 
 | 
     * @param obj 
 | 
     * @param clazz 
 | 
     * @param <T> 
 | 
     * @return 
 | 
     */ 
 | 
    public static final <T> List<T> toList(Object obj, Class<T> clazz) { 
 | 
        if (obj == null) { 
 | 
            return null; 
 | 
        } 
 | 
        return JSONArray.parseArray(obj.toString(), clazz); 
 | 
    } 
 | 
} 
 |