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

The following examples show how to use com.github.knightliao.apollo.utils.data.JsonUtils. 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: WebCommonInterceptor.java    From disconf with 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 File: RedisClient.java    From apollo with 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 File: RedisClient.java    From apollo with 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 File: WebCommonInterceptor.java    From disconf with 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));
}