Closed nicolasard closed 1 year ago
Hi @nicolasard ,
I wonder if there si something like Response that I can use that wraps the custom entity object with the header values.
I'm not sure that such a "custom" Response wrapper with both your custom response entity and the response header exists.
But maybe you can create this Response wrapper and register a custom MessageBodyReader<T>
to convert the HTTP stream into this Response wrapper. Something like that :
public class CustomJacksonAnotatedResponseWrapper {
private CustomJacksonAnotatedResponse responseEntity;
private MultivaluedMap<String, String> responseHeaders;
....
}
public class MessageBodyReaderImpl implements MessageBodyReader<CustomJacksonAnotatedResponseWrapper> {
...
@Override
public CustomJacksonAnotatedResponseWrapper readFrom(Class<CustomJacksonAnotatedResponseWrapper> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
CustomJacksonAnotatedResponseWrapper customResponseEntityWrapper = new CustomJacksonAnotatedResponseWrapper();
customResponseEntityWrapper.setResponseHeaders(httpHeaders);
customResponseEntityWrapper.setResponseEntity(objectMapper.read(entityStream, CustomJacksonAnotatedResponse.class));
return customResponseEntityWrapper;
}
}
-- Nicolas
This should really be a discussion on https://github.com/resteasy/resteasy/discussions. This is discussion area is for the Jakarta RESTful Web Services specification of which RESTEasy is an implementation of.
Closing given that Rest Client is in MP.
Hello, I can't find how I can write a proper interface definition that is able to parse the payload and the headers of the response.
If I write the following interface, with restEasy I can get the response properly and that's deserialized. But I want to read the response headers too.
Then to read the headers I can do this and use javax.ws.rs.core.Response
I can get the entity now from the Response and the headers. But I is not clear by reading the interface what type of response object we expect. I wonder if there si something like Response that I can use that wraps the custom entity object with the header values.