@Override public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream inputStream) throws IOException { Object object; try { JsonParser jsonParser = objectMapper.getFactory().createParser(inputStream); // Important: we are NOT to close the underlying stream after // mapping, so we need to instruct parser: jsonParser.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE); object = objectMapper.readValue(jsonParser, objectMapper.getTypeFactory().constructType(genericType)); } catch (Exception e) { // We want to handle parsing exceptions differently than regular IOExceptions so just rethrow IOExceptions if (e instanceof IOException && !(e instanceof JsonProcessingException) && !(e instanceof EOFException)) { throw e; } // log the exception at debug so it can be viewed during development // Note: we are not logging at a higher level because this could cause a denial of service log.debug(e, "Invalid json for Java type %s", type); // Invalid json request. Throwing exception so the response code can be overridden using a mapper. throw new JsonMapperParsingException(type, e); } return object; }
assertTrue((e.getMessage()).startsWith("Invalid json for Java type"));
assertTrue((e.getMessage()).startsWith("Invalid json for Java type"));
@Override public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream inputStream) throws IOException { Object object; try { JsonParser jsonParser = objectMapper.getFactory().createParser(inputStream); // Important: we are NOT to close the underlying stream after // mapping, so we need to instruct parser: jsonParser.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE); object = objectMapper.readValue(jsonParser, objectMapper.getTypeFactory().constructType(genericType)); } catch (Exception e) { // We want to handle parsing exceptions differently than regular IOExceptions so just rethrow IOExceptions if (e instanceof IOException && !(e instanceof JsonProcessingException) && !(e instanceof EOFException)) { throw e; } // log the exception at debug so it can be viewed during development // Note: we are not logging at a higher level because this could cause a denial of service log.debug(e, "Invalid json for Java type %s", type); // Invalid json request. Throwing exception so the response code can be overridden using a mapper. throw new JsonMapperParsingException(type, e); } return object; }
@Override public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream inputStream) throws IOException { Object object; try { JsonParser jsonParser = new SmileFactory().createParser(inputStream); // Important: we are NOT to close the underlying stream after // mapping, so we need to instruct parser: jsonParser.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE); object = objectMapper.readValue(jsonParser, objectMapper.getTypeFactory().constructType(genericType)); } catch (Exception e) { // we want to return a 400 for bad JSON but not for a real IO exception if (e instanceof IOException && !(e instanceof JsonProcessingException) && !(e instanceof EOFException)) { throw (IOException) e; } // log the exception at debug so it can be viewed during development // Note: we are not logging at a higher level because this could cause a denial of service log.debug(e, "Invalid json for Java type %s", type); // Invalid json request. Throwing exception so the response code can be overridden using a mapper. throw new JsonMapperParsingException(type, e); } return object; }
@Override public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream inputStream) throws IOException { Object object; try { JsonParser jsonParser = new SmileFactory().createParser(inputStream); // Important: we are NOT to close the underlying stream after // mapping, so we need to instruct parser: jsonParser.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE); object = objectMapper.readValue(jsonParser, objectMapper.getTypeFactory().constructType(genericType)); } catch (Exception e) { // we want to return a 400 for bad JSON but not for a real IO exception if (e instanceof IOException && !(e instanceof JsonProcessingException) && !(e instanceof EOFException)) { throw (IOException) e; } // log the exception at debug so it can be viewed during development // Note: we are not logging at a higher level because this could cause a denial of service log.debug(e, "Invalid json for Java type %s", type); // Invalid json request. Throwing exception so the response code can be overridden using a mapper. throw new JsonMapperParsingException(type, e); } return object; }