users@jersey.java.net

[Jersey] media type determined before response filtering causes incorrect writer to be selected

From: spamdaemon <spamdaemon_at_comcast.net>
Date: Sun, 14 Jul 2013 15:00:29 -0400

I'm in the process of converting my code over to jersey2 and I've run into a
problem with container response filters.


In a nutshell, I've got a a resource that returns an entity of type X<T> and
my filter wraps it as GenericEntity for which there exists a writer (for
some T, but not all)
The problem is that it has determined the mimetype based on X<T> and not
GenericEntity<X<T>> and so it selects the wrong writer.


What seems to be happening is that response's mediatype is determined
and set before any response filters are executed.
If I change the entity in the response filter without setting a media type,
then the pre-determined mediatype is used to a select a writer; in my case
(involving GenericEntity objects) it selects the wrong writer.


So here are my questions:
1. Is this a change from jax-rs 1 or this is jersey specific?
2. Is there a way to use filter priority to achieve what I want?
3. How else could I change the entity in response filter and have it
select the correct writer automatically?