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