/** * Writes a JSON string corresponding to the given object a {@link Response}. * * @param status * the error status. * @param object * the error object. * @return the response containing JSON entity. */ protected Response toResponse(final Response.StatusType status, final Object object) { return Response.status(status).type(MediaType.APPLICATION_JSON_TYPE).entity(toEntity(object)).build(); }
/** * Writes a JSON string corresponding to the given error to a {@link Response}. * * @param status * the error status. * @param errorKey * the error key that will be used for localization. * @param ex * the technical exception. * @return the response containing JSON entity. */ protected Response toResponse(final Response.StatusType status, final String errorKey, final Throwable ex) { final ServerError serverError = new ServerError(); serverError.setCode(errorKey); if (ex != null) { serverError.setThrowable(ex); } if (ex instanceof AbstractParameteredException && ((AbstractParameteredException) ex).getParameters().length > 0) { serverError.setParameters(((AbstractParameteredException) ex).getParameters()); } return toResponse(status, serverError); }