com.jfinal.kit.JsonKit Java Examples

The following examples show how to use com.jfinal.kit.JsonKit. 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: NoticeRequest.java    From sdb-mall with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
	NoticeRequest req = new NoticeRequest();
	req.setBillstatus("polling");
	req.setMessage("到达");
	req.setStatus("check");
	req.getLastResult().setCom("yauntong");
	req.getLastResult().setCondition("F00");
	req.getLastResult().setIscheck("0");
	req.getLastResult().setNu("V030344422");
	req.getLastResult().setState("0");
	req.getLastResult().setStatus("200");
	req.getLastResult().setMessage("ok");
	ResultItem item = new ResultItem();
	item.setContext("上海分拨中心/装件入车扫描 ");
	item.setFtime("2012-08-28 16:33:19");
	item.setTime("2012-08-28 16:33:19");
	req.getLastResult().getData().add(item);
	item = new ResultItem();
	item.setContext("上海分拨中心/下车扫描");
	item.setFtime("2012-08-27 23:22:42");
	item.setTime("2012-08-27 23:22:42");
	req.getLastResult().getData().add(item);
	System.out.println(JsonKit.toJson(req));
}
 
Example #2
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 #3
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 #4
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 #5
Source File: UserController.java    From jboot-admin with Apache License 2.0 4 votes vote down vote up
@Override
public Object doSaveOrUpdateUserByApiResult(ApiResult apiResult) {
    // 根据自己需求扩展,比如保存微信用户信息,与内部用户做关联
    System.out.println(JsonKit.toJson(apiResult));
    return apiResult;
}
 
Example #6
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 #7
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 #8
Source File: GatewaySentinelProcesser.java    From jboot with Apache License 2.0 4 votes vote down vote up
private static void writeDefaultBlockedJson(HttpServletResponse resp, Map map) throws IOException {
    resp.setStatus(200);
    resp.setContentType(contentType);
    PrintWriter out = resp.getWriter();
    out.print(JsonKit.toJson(map));
}
 
Example #9
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 #10
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 #11
Source File: JbootController.java    From jboot with Apache License 2.0 2 votes vote down vote up
/**
 * 接收 json 转化为 object
 *
 * @param tClass
 * @param <T>
 * @return
 */
@NotAction
public <T> T getRawObject(Class<T> tClass) {
    return StrUtil.isBlank(getRawData()) ? null : JsonKit.parse(getRawData(), tClass);
}