|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.ws.rs.core.GenericEntity<T>
public class GenericEntity<T>
Represents a response entity of a generic type T
.
Normally type erasure removes generic type information such that a
Response
instance that contains, e.g., an entity of type
List<String>
appears to contain a raw List<?>
at runtime.
When the generic type is required to select a suitable
MessageBodyWriter
, this class may be used to wrap the entity and
capture its generic type.
Users are required to create a (typically anonymous) subclass of this
class which enables retrieval of the type information at runtime despite
type erasure. For example, the following code shows how to create a
Response
containing an entity of type List<String>
whose
generic type will be available at runtime for selection of a suitable
MessageBodyWriter
:
List<String> list = new ArrayList<String>(); GenericEntity<List<String>> entity = new GenericEntity<List<String>>(list) {}; Response response = Response.ok(entity);
where list
is the instance of List<String>
that will form the response body and entity is an instance of an anonymous
subclass of GenericEntity
.
Constructor Summary | |
---|---|
protected |
GenericEntity(T entity)
Constructs a new generic entity. |
Method Summary | |
---|---|
T |
getEntity()
Get the enclosed entity |
java.lang.Class<?> |
getRawType()
Gets the raw type of the enclosed entity. |
java.lang.reflect.Type |
getType()
Gets underlying Type instance. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected GenericEntity(T entity)
entity
- the entity instance, must not be null
java.lang.IllegalArgumentException
- if entity is nullMethod Detail |
---|
public final java.lang.Class<?> getRawType()
ArrayList
not List
.
public final java.lang.reflect.Type getType()
Type
instance. Note that this is derived from the
type parameter, not the enclosed instance. I.e. in the example
in the introduction, the type is List<String>
not
ArrayList<String>
.
public final T getEntity()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |