Java Code Examples for com.github.knightliao.apollo.utils.data.JsonUtils

The following examples show how to use com.github.knightliao.apollo.utils.data.JsonUtils. These examples are extracted from open source projects. 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 Project: disconf   Source File: WebCommonInterceptor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 自定义的全局错误
 *
 * @param request
 * @param response
 * @param message
 * @param errorCode
 *
 * @throws IOException
 */
protected void returnJsonSystemError(HttpServletRequest request, HttpServletResponse response, String message,
                                     ErrorCode errorCode) throws IOException {

    JsonObjectBase jsonObjectBase = JsonObjectUtils.buildGlobalError(message, errorCode);

    response.setHeader("Cache-Control", "no-cache");
    response.setContentType("application/json;charset=UTF-8");
    response.setCharacterEncoding("UTF-8");

    response.getWriter().write(JsonUtils.toJson(jsonObjectBase));
}
 
Example 2
Source Project: apollo   Source File: RedisClient.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the bytes representing the given serialized object.
 */
protected byte[] jsonSerialize(Object o) {
    byte[] res = null;
    try {
        res = JsonUtils.toJson(o).getBytes("utf-8");
    } catch (UnsupportedEncodingException e) {
        logger.error("JsonSerialize object fail ", e);
    }
    return res;
}
 
Example 3
Source Project: apollo   Source File: RedisClient.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the object represented by the given serialized bytes.
 */
protected Object jsonDeserialize(byte[] in, Class<?> cls) {
    if (in == null || in.length == 0) {
        return null;
    }
    Object res = null;
    try {
        res = JsonUtils.json2Object(new String(in, "utf-8"), cls);
    } catch (UnsupportedEncodingException e) {
        logger.error("DeSerialize object fail ", e);
    }
    return res;
}
 
Example 4
Source Project: disconf   Source File: WebCommonInterceptor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 自定义的全局错误
 *
 * @param request
 * @param response
 * @param message
 * @param errorCode
 *
 * @throws IOException
 */
protected void returnJsonSystemError(HttpServletRequest request, HttpServletResponse response, String message,
                                     ErrorCode errorCode) throws IOException {

    JsonObjectBase jsonObjectBase = JsonObjectUtils.buildGlobalError(message, errorCode);

    response.setHeader("Cache-Control", "no-cache");
    response.setContentType("application/json;charset=UTF-8");
    response.setCharacterEncoding("UTF-8");

    response.getWriter().write(JsonUtils.toJson(jsonObjectBase));
}