@Test(expected = JsonParseException.class) public void readFrom_noValidation_jsonParseError() throws Exception { annotations = new Annotation[] { createMock(Annotation.class) }; @SuppressWarnings("unchecked") MultivaluedMap<String, String> httpHeaders = createMock(MultivaluedMap.class); InputStream entityStream = createMock(InputStream.class); expect(annotations[0].annotationType()).andStubReturn(null); expect(delegate.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream)) .andThrow(createMock(JsonParseException.class)); replayAll(); provider.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream); }
@Override public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { Object value = parseEntity(type, genericType, annotations, mediaType, httpHeaders, entityStream); if (hasValidAnnotation(annotations)) { List<String> errors = validate(value); if (!errors.isEmpty()) { StringBuilder msg = new StringBuilder("The request entity had the following errors:\n"); for (String error : errors) { msg.append(" * ").append(error).append('\n'); } throw new WebApplicationException(unprocessableEntity(msg.toString())); } } return value; }
ValidatingJacksonJsonProvider implements MessageBodyReader<Object>, MessageBodyWriter<Object> { @Override public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { Object value = parseEntity(type, genericType, annotations, mediaType, httpHeaders, entityStream); if (hasValidAnnotation(annotations)) { List<String> errors = validate(value); if (!errors.isEmpty()) { StringBuilder msg = new StringBuilder("The request entity had the following errors:\n"); for (String error : errors) { msg.append(" * ").append(error).append('\n'); } throw new WebApplicationException(unprocessableEntity(msg.toString())); } } return value; } }
ValidatingJacksonJsonProvider implements MessageBodyReader<Object>, MessageBodyWriter<Object> { @Override public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { Object value = parseEntity(type, genericType, annotations, mediaType, httpHeaders, entityStream); if (hasValidAnnotation(annotations)) { List<String> errors = validate(value); if (!errors.isEmpty()) { StringBuilder msg = new StringBuilder("The request entity had the following errors:\n"); for (String error : errors) { msg.append(" * ").append(error).append('\n'); } throw new WebApplicationException(unprocessableEntity(msg.toString())); } } return value; } @Inject  ValidatingJacksonJsonProvider(JacksonJsonProvider delegate, Validator validator); }
ValidatingJacksonJsonProvider implements MessageBodyReader<Object>, MessageBodyWriter<Object> { @Override public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { Object value = parseEntity(type, genericType, annotations, mediaType, httpHeaders, entityStream); if (hasValidAnnotation(annotations)) { List<String> errors = validate(value); if (!errors.isEmpty()) { StringBuilder msg = new StringBuilder("The request entity had the following errors:\n"); for (String error : errors) { msg.append(" * ").append(error).append('\n'); } throw new WebApplicationException(unprocessableEntity(msg.toString())); } } return value; } @Inject  ValidatingJacksonJsonProvider(JacksonJsonProvider delegate, Validator validator); @Override Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations,
      MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream); @Override void writeTo(Object t, Class<?> type, Type genericType, Annotation[] annotations,
      MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream); @Override boolean isWriteable(Class<?> type, Type genericType,
      Annotation[] annotations, MediaType mediaType); @Override long getSize(Object t, Class<?> type, Type genericType,
      Annotation[] annotations, MediaType mediaType); @Override boolean isReadable(Class<?> type, Type genericType,
      Annotation[] annotations, MediaType mediaType); }
ValidatingJacksonJsonProvider implements MessageBodyReader<Object>, MessageBodyWriter<Object> { @Override public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { Object value = parseEntity(type, genericType, annotations, mediaType, httpHeaders, entityStream); if (hasValidAnnotation(annotations)) { List<String> errors = validate(value); if (!errors.isEmpty()) { StringBuilder msg = new StringBuilder("The request entity had the following errors:\n"); for (String error : errors) { msg.append(" * ").append(error).append('\n'); } throw new WebApplicationException(unprocessableEntity(msg.toString())); } } return value; } @Inject  ValidatingJacksonJsonProvider(JacksonJsonProvider delegate, Validator validator); @Override Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations,
      MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream); @Override void writeTo(Object t, Class<?> type, Type genericType, Annotation[] annotations,
      MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream); @Override boolean isWriteable(Class<?> type, Type genericType,
      Annotation[] annotations, MediaType mediaType); @Override long getSize(Object t, Class<?> type, Type genericType,
      Annotation[] annotations, MediaType mediaType); @Override boolean isReadable(Class<?> type, Type genericType,
      Annotation[] annotations, MediaType mediaType);  }