Basically, I implemented MessageBodyReader within the context of using restful web service.
But I think my issue is more toward understanding Java related than restful feature.
Generics is black hole for me in general :-D
H Paul wrote:
How do we test for the genericity of java.util.List<org.concepts.domain.Computer>
It depends on what you mean by that. Taking an educated guess at what you might mean, I would say we try to add 1) Computer, 2) subclass of Computer, and 3) non-Computer to the list, and then we verify that 1 and 2 compile and 3 gives a compile error. We could further retrieve from the list and verify that declaring the result as Computer without casting does not cause a compiler error.
H Paul wrote:How do we test for the genericity of java.util.List<org.concepts.domain.Computer>
You don't. Or at least, you shouldn't.
You're in the realm of Object-Orientation here. If you plan on checking types and then dispatching code based on that, then you're either:
(a) Doing something wrong, or
(b) Into the realm of execution-time binding, which Java was never intended to solve.
Why don't you back up and tell us what you want to do; not how you want to do it?
Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
Joined: Jul 26, 2011
1. Client (jax-rs) send a GET to the server
2. The server send back a JSON string in the form of an JSON Array.
3. Client (jax-rs) need to convert this JSON string into a Java List that I need.
4. Client (jax-rs) call my custom code to convert JSON string into a Java List.
5. The Client (jax-rs) ask my custom code isReadable to produce a Java List? (return true/false)
If my isReadable OK (true), then the Client will call readFrom to convert the JSON string into a Java List.
The issue here is at isReadable (how do I test for genericity of List<Computer>
what is this line mean?
genericType - the type of object to be produced. E.g. if the message body is to be converted into a method parameter, this will be the formal type of the method parameter as returned by Method.getGenericParameterTypes.
Joined: Jul 26, 2011
A generic type is a type with formal type parameters.
A parameterized type is an instantiation of a generic type with actual type arguments.