Hi All,
I am using Jersey framework 1.17 for my RESTful servces.
But I got a question about the design of the MessageBodyReader interface.
public interface MessageBodyReader<T> {
boolean isReadable(Class<?> type, Type genericType,
Annotation annotations[], MediaType mediaType);
T readFrom(Class<T> type, Type genericType,
Annotation annotations[], MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream) throws IOException,
WebApplicationException;
}
Seems that we need write exactly one MessageBodyReader implementation per
Class because of the type parameter T of the readFrom method argument list,
right?
The problem here is that Class<S> or Class<?> cannot assigned to Class<T>,
even though S is a subclass of T.
So I am wondering how to write a MessageBodyReader that can read all the
classes that are subclasses of one specific class C instead write lots of
concrete implementations?