Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jaxrs-dev] Request for clarification [Response.fromResponse()]

This request arises from JIRA issue RESTEASY-1399 "org.jboss.resteasy.specimpl.BuiltResponse.getEntity() should return the original GenericEntity<>" (https://issues.jboss.org/browse/RESTEASY-1399).

We are unclear about the semantics of javax.ws.rs.core.Response.fromResponse(). particularly the lines

        ResponseBuilder b = status(response.getStatus());
        if (response.hasEntity()) {
            b.entity(response.getEntity());

Consider

Response.ok(new GenericEntity<List<Bean>>(Arrays.<Bean>asList(new Bean("a"), new Bean("b"))) {}).build();

It is clear from the Response.ok() javadoc that the "actual entity" is a List<> and not a GenericEntity<>.  Presumably, then, Response.getEntity(), which, according to the javadoc, returns "the message entity Java instance", should return the List<>. But what about

            b.entity(response.getEntity());

in Response.fromResponse(). The javadoc for Response.fromResponse() says "The original response entity instance reference is set in the new response builder." According to the code, the new Response will be the original List<>. But that means that the generic type of the List<> will be lost, which seems to be a problem, since the generic type can be used by, for example, MessageBodyWriter.writeTo().

Two possible solutions have been suggested in our discussions.

1. Response.getEntity() should be redefined to return the object with which the Response was created; in the example above, it would be the GenericEntity<>.

2. Add methods
a. Response.getGenericType() and
b. ResponseBuilder.setGenericType()

so that Response.fromResponse() could be written

        ResponseBuilder b = status(response.getStatus());
        if (response.hasEntity()) {
            b.entity(response.getEntity());
            b.setGenericType(response.getGenericType());
            ...

Personally, I think the first option has significant consequences that are best avoided. The second option, though, proposes simple extensions rather than changes.

-Ron





-- 
My company's smarter than your company (unless you work for Red Hat)

Back to the top