工具类:JavaBeanUtil

来源:互联网 发布:德州淘宝村 编辑:程序博客网 时间:2024/05/22 08:25
package com.hxsmart.intelligentizepos.util;import com.google.gson.Gson;/** * Developer : xiongwenwei@aliyun.com * Create Time :2016-5-23 17:49:45 * Function:将json字符串转为JavaBean */public class BeanUtil {    private static Gson gson = null;    static {        if (gson == null) {            gson = new Gson();        }    }    /**     * 将json转为bean     * @param jsonString     * @param cls     * @return bean     */    public static <T> T getBean(String jsonString, Class<T> cls) {        T t = null;        if (gson != null) {            t = gson.fromJson(jsonString, cls);        }        return t;    }}

0 0