Java Code Examples for com.jfinal.kit.JsonKit#toJson()

The following examples show how to use com.jfinal.kit.JsonKit#toJson() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JbootResponseEntityRender.java    From jboot with Apache License 2.0 6 votes vote down vote up
@Override
public void render() {

    PrintWriter writer = null;
    try {
        //默认输出 json,但是 responseEntity 可以配置 Header 覆盖这个输出
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Content-Type", "application/json; charset=utf-8");
        response.setStatus(responseEntity.getHttpStatus().value());

        Map<String, String> headers = responseEntity.getHeaders();
        if (headers != null && !headers.isEmpty()) {
            for (Map.Entry<String, String> entry : headers.entrySet()) {
                response.setHeader(entry.getKey(), entry.getValue());
            }
        }

        String jsonText = responseEntity.getBody() == null ? "" : JsonKit.toJson(responseEntity.getBody());
        writer = response.getWriter();
        writer.write(jsonText);
        // writer.flush();
    } catch (IOException e) {
        throw new RenderException(e);
    }

}
 
Example 2
Source File: JbootReturnValueRender.java    From jboot with Apache License 2.0 5 votes vote down vote up
public JbootReturnValueRender(Action action, Object returnValue) {

        this.action = action;

        if (returnValue == null) {
            this.value = null;
        } else if (isBaseType(returnValue)) {
            this.value = String.valueOf(returnValue);
        } else {
            this.value = returnValue;
        }

        if (this.value == null) {
            this.render = new NullRender();
        } else if (this.value instanceof ResponseEntity) {
            this.render = new JbootResponseEntityRender((ResponseEntity) value);
        } else if (this.value instanceof String) {
            this.render = new TextRender((String) value);
        } else if (this.value instanceof Date) {
            this.render = new TextRender(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((Date) value));
        } else if (this.value instanceof File) {
            this.render = new FileRender((File) value);
        } else if (this.value instanceof Render) {
            this.render = (Render) value;
        } else {
            this.render = new JsonRender(JsonKit.toJson(value));
        }
    }
 
Example 3
Source File: JwtManager.java    From jboot with Apache License 2.0 5 votes vote down vote up
public String createJwtToken(Map map) {

        if (!getConfig().isConfigOk()) {
            throw new JbootException("can not create jwt, please config jboot.web.jwt.secret in jboot.properties.");
        }

        SecretKey secretKey = generalKey();

        SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
        long nowMillis = System.currentTimeMillis();
        Date now = new Date(nowMillis);

        map.put(JwtInterceptor.ISUUED_AT, nowMillis);
        String subject = JsonKit.toJson(map);

        JwtBuilder builder = Jwts.builder()
                .setIssuedAt(now)
                .setSubject(subject)
                .signWith(signatureAlgorithm, secretKey);

        if (getConfig().getValidityPeriod() > 0) {
            long expMillis = nowMillis + getConfig().getValidityPeriod();
            builder.setExpiration(new Date(expMillis));
        }

        return builder.compact();
    }
 
Example 4
Source File: Result.java    From sdb-mall with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return JsonKit.toJson(this);
}
 
Example 5
Source File: TaskRequest.java    From sdb-mall with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return JsonKit.toJson(this);
}
 
Example 6
Source File: Action.java    From jpress with GNU Lesser General Public License v3.0 4 votes vote down vote up
public String toJson() {
    Action[] actions = new Action[]{this};
    return JsonKit.toJson(actions);
}
 
Example 7
Source File: Action.java    From jpress with GNU Lesser General Public License v3.0 4 votes vote down vote up
public String toJson() {
    Action[] actions = new Action[]{this};
    return JsonKit.toJson(actions);
}