ListMultipartFormDataMessageBodyReader implements MessageBodyReader<List<InputItem>> { @Override public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { if (type == List.class && genericType instanceof ParameterizedType) { ParameterizedType t = (ParameterizedType)genericType; Type[] ta = t.getActualTypeArguments(); return ta.length == 1 && ta[0] == InputItem.class; } return false; } ListMultipartFormDataMessageBodyReader(@Context Providers providers); @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override List<InputItem> readFrom(Class<List<InputItem>> type, Type genericType, Annotation[] annotations, MediaType mediaType,
                                    MultivaluedMap<String, String> httpHeaders, InputStream entityStream);  }
@Test public void isReadableForListOfInputItems() throws Exception { Class<List> type = List.class; ParameterizedType genericType = newParameterizedType(List.class, InputItem.class); assertTrue(listMultipartFormDataMessageBodyReader.isReadable(type, genericType, new Annotation[0], null)); }
@Test public void isNotReadableForListOfOtherTypeThanInputItem() throws Exception { Class<List> type = List.class; ParameterizedType genericType = newParameterizedType(List.class, String.class); assertFalse(listMultipartFormDataMessageBodyReader.isReadable(type, genericType, new Annotation[0], null)); }
@Test public void isNotReadableForOtherCollectionOfInputItems() throws Exception { Class<Collection> type = Collection.class; ParameterizedType genericType = newParameterizedType(Collection.class, InputItem.class); assertFalse(listMultipartFormDataMessageBodyReader.isReadable(type, genericType, new Annotation[0], null)); }
@Test public void isNotReadableWhenGenericTypeIsNotAvailable() throws Exception { Class<List> type = List.class; assertFalse(listMultipartFormDataMessageBodyReader.isReadable(type, null, new Annotation[0], null)); }