Code example for GsonBuilder

Methods: create

0
     */ 
    public static <T> T fromJson(String json, TypeToken<T> token, String datePattern) {
        if (StringUtils.isEmpty(json)) {
            return null; 
        } 
        GsonBuilder builder = new GsonBuilder();
        if (StringUtils.isEmpty(datePattern)) {
            datePattern = DEFAULT_DATE_PATTERN;
        } 
        Gson gson = builder.create();
        try { 
            return gson.fromJson(json, token.getType());
        } catch (Exception ex) {
            log.error(json + " 无法转换为 " + token.getRawType().getName() + " 对象!", ex);
            ex.printStackTrace();
            return null; 
        } 
    } 
 
    /** 
Experience pair programming with AI  Get Codota for Java