src/main/java/com/jmsoftware/datastructuresandalgorithms/common/util/ResponseUtil.java
/**
     * Write exception JSON to response.
     *
     * @param response  Response
     * @param exception Exception
     */
Write exception JSON to response.
@param response  Response
@param exception Exception
Write exception JSON to response . @param response Response @param exception Exception
public static void renderJson(final HttpServletResponse response, final BaseException exception) {
        val httpStatus = HttpStatus.fromCode(exception.getCode());
        standardizeHttpServletResponse(response, httpStatus);
        val responseBodyBean = ResponseBodyBean.ofStatus(exception.getCode(),
                                                                              exception.getMessage(),
                                                                              exception.getData());
        try {
            response.getWriter().write(MAPPER.writeValueAsString(responseBodyBean));
        } catch (IOException e) {
            log.error("Error occurred when responding an exception JSON.", e);
        }
    }
public static void renderJson ( final HttpServletResponse response , final BaseException exception ) { val httpStatus = HttpStatus . fromCode ( exception . getCode ( ) ) ; standardizeHttpServletResponse ( response , httpStatus ) ; val responseBodyBean = ResponseBodyBean . ofStatus ( exception . getCode ( ) , exception . getMessage ( ) , exception . getData ( ) ) ; try { response . getWriter ( ) . write ( MAPPER . writeValueAsString ( responseBodyBean ) ) ; } catch ( IOException e ) { log . error ( "Error occurred when responding an exception JSON." , e ) ; } }
Write exception JSON to response.
Write exception JSON to response .