- Add the Codota plugin to your IDE and get smart completions
private void myMethod () {}
public <T> T parse(String jsonString, Class<T> type) { return fastJson.parse(jsonString, type); } }
public Json getJson() { return new FastJson(); }
public String toJson(Object object) { // 优先使用对象级的属性 datePattern, 然后才是全局性的 defaultDatePattern String dp = datePattern != null ? datePattern : getDefaultDatePattern(); if (dp == null) { return JSON.toJSONString(object); } else { return JSON.toJSONStringWithDateFormat(object, dp, SerializerFeature.WriteDateUseDateFormat); // return JSON.toJSONString(object, SerializerFeature.WriteDateUseDateFormat); } }
/** * 将 json字符串 转为Object * @param jsonString json字符串 * @param valueType 结果类型 * @param <T> 泛型标记 * @return T 结果 */ public static <T> T parse(String jsonString, Class<T> valueType) { if (jsonFactory == null) { // return Json.getJson().parse(jsonString, valueType); Json json = Json.getJson(); // JFinalJson 不支持 parse if (json instanceof com.jfinal.json.JFinalJson) { return FastJson.getJson().parse(jsonString, valueType); } else { return json.parse(jsonString, valueType); } } return jsonFactory.getJson().parse(jsonString, valueType); }
public String createJwtToken(Map map) { SecretKey secretKey = generalKey(); SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256; long nowMillis = System.currentTimeMillis(); Date now = new Date(nowMillis); map.put("isuuedAt", nowMillis); String subject = FastJson.getJson().toJson(map); JwtBuilder builder = Jwts.builder() .setIssuedAt(now) .setSubject(subject) .signWith(signatureAlgorithm, secretKey); if (jwtConfig.getValidityPeriod() > 0) { long expMillis = nowMillis + jwtConfig.getValidityPeriod(); builder.setExpiration(new Date(expMillis)); } return builder.compact(); }
public Map parseJwtToken(String token) { SecretKey secretKey = generalKey(); try { Claims claims = Jwts.parser() .setSigningKey(secretKey) .parseClaimsJws(token).getBody(); String subject = claims.getSubject(); if (StrUtils.isBlank(subject)) { return null; } return FastJson.getJson().parse(subject, HashMap.class); } catch (SignatureException | MalformedJwtException e) { // don't trust the JWT! // jwt 签名错误或解析错误,可能是伪造的,不能相信 } catch (ExpiredJwtException e) { // jwt 已经过期 } catch (Throwable ex) { //其他错误 } return null; }
public <T> T parse(String jsonString, Class<T> type) { return fastJson.parse(jsonString, type); } }
public static FastJson getJson() { return new FastJson(); }
public String toJson(Object object) { // 优先使用对象级的属性 datePattern, 然后才是全局性的 defaultDatePattern String dp = datePattern != null ? datePattern : getDefaultDatePattern(); if (dp == null) { return JSON.toJSONString(object); } else { return JSON.toJSONStringWithDateFormat(object, dp, SerializerFeature.WriteDateUseDateFormat); // return JSON.toJSONString(object, SerializerFeature.WriteDateUseDateFormat); } }
public static FastJson getJson() { return new FastJson(); }
public Json getJson() { return new FastJson(); }