Java Code Examples for com.fasterxml.jackson.core.JsonProcessingException#getOriginalMessage()
The following examples show how to use
com.fasterxml.jackson.core.JsonProcessingException#getOriginalMessage() .
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: ExceptionHandlerControllerAdvice.java From OpenLRW with Educational Community License v2.0 | 6 votes |
@ExceptionHandler(HttpMessageNotReadableException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public MessageResponse handleHttpMessageNotReadableException(HttpServletRequest request, HttpMessageNotReadableException e) { if (e.getCause() instanceof UnrecognizedPropertyException) { return handleUnrecognizedPropertyException(request, (UnrecognizedPropertyException)e.getCause()); } else { MessageResponse response; if (e.getCause() instanceof JsonProcessingException) { JsonProcessingException jpe = (JsonProcessingException)e.getCause(); response = new MessageResponse(HttpStatus.BAD_REQUEST, buildDate(), request, jpe.getOriginalMessage()); } else { response = new MessageResponse(HttpStatus.BAD_REQUEST, buildDate(), request, e.getMessage()); } log(e, response); return response; } }
Example 2
Source File: TitusExceptionMapper.java From titus-control-plane with Apache License 2.0 | 6 votes |
private Response fromJsonProcessingException(JsonProcessingException e) { StringBuilder msgBuilder = new StringBuilder(); if (e.getOriginalMessage() != null) { msgBuilder.append(e.getOriginalMessage()); } else { msgBuilder.append("JSON processing error"); } JsonLocation location = e.getLocation(); if (location != null) { msgBuilder.append(" location: [line: ").append(location.getLineNr()) .append(", column: ").append(location.getColumnNr()).append(']'); } ErrorResponse errorResponse = ErrorResponse.newError(HttpServletResponse.SC_BAD_REQUEST, msgBuilder.toString()) .clientRequest(httpServletRequest) .serverContext() .exceptionContext(e) .build(); return Response.status(Status.BAD_REQUEST).entity(errorResponse).build(); }
Example 3
Source File: AbstractJackson2HttpMessageConverter.java From lams with GNU General Public License v2.0 | 4 votes |
@Override protected void writeInternal(Object object, Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { MediaType contentType = outputMessage.getHeaders().getContentType(); JsonEncoding encoding = getJsonEncoding(contentType); JsonGenerator generator = this.objectMapper.getFactory().createGenerator(outputMessage.getBody(), encoding); try { writePrefix(generator, object); Class<?> serializationView = null; FilterProvider filters = null; Object value = object; JavaType javaType = null; if (object instanceof MappingJacksonValue) { MappingJacksonValue container = (MappingJacksonValue) object; value = container.getValue(); serializationView = container.getSerializationView(); filters = container.getFilters(); } if (type != null && value != null && TypeUtils.isAssignable(type, value.getClass())) { javaType = getJavaType(type, null); } ObjectWriter objectWriter; if (serializationView != null) { objectWriter = this.objectMapper.writerWithView(serializationView); } else if (filters != null) { objectWriter = this.objectMapper.writer(filters); } else { objectWriter = this.objectMapper.writer(); } if (javaType != null && javaType.isContainerType()) { objectWriter = objectWriter.forType(javaType); } SerializationConfig config = objectWriter.getConfig(); if (contentType != null && contentType.isCompatibleWith(TEXT_EVENT_STREAM) && config.isEnabled(SerializationFeature.INDENT_OUTPUT)) { objectWriter = objectWriter.with(this.ssePrettyPrinter); } objectWriter.writeValue(generator, value); writeSuffix(generator, object); generator.flush(); } catch (JsonProcessingException ex) { throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getOriginalMessage(), ex); } }
Example 4
Source File: JsonProcessingExceptionMapper.java From ameba with MIT License | 4 votes |
/** * {@inheritDoc} */ @Override public Response toResponse(JsonProcessingException exception) { Throwable throwable = exception; while (throwable != null) { if (throwable instanceof PersistenceException) { return exceptionMappers.get().findMapping(throwable).toResponse(throwable); } throwable = throwable.getCause(); } logger.debug("Json Processing error", exception); String message = exception.getOriginalMessage(); String desc = null; String source = null; if (mode.isDev()) { desc = IOUtils.getStackTrace(exception); JsonLocation location = exception.getLocation(); if (location != null) { source = "line: " + location.getLineNr() + ", column: " + location.getColumnNr(); } else { source = exception.getStackTrace()[0].toString(); } } ErrorMessage errorMessage = ErrorMessage.fromStatus(Response.Status.BAD_REQUEST.getStatusCode()); errorMessage.setThrowable(exception); errorMessage.setCode(Hashing.murmur3_32().hashUnencodedChars(exception.getClass().getName()).toString()); errorMessage.addError(new Result.Error( errorMessage.getCode(), message != null ? message : exception.getMessage(), desc, source )); return Response.status(errorMessage.getStatus()) .entity(errorMessage) .type(ExceptionMapperUtils.getResponseType()) .build(); }