users@jersey.java.net

[Jersey] Re: Jersey(2.10.4) Entity provider selection algorithm gives less priority to custom providers(MessageBodyWriter) making it not to be invoked

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Fri, 20 Feb 2015 12:41:33 +0100

If your custom MBW has the same Java type and media type distance as any default MBW shipped with Jersey, then your MBW will take precedence (if not, there is a bug). So, to make Jersey pick your provider, it needs to be at least as specific (in terms of produced media type and Java type) as the most specific default provider.

It would be good if you could provide a use case that does not work as you would expect. Also you can enable tracing <https://jersey.java.net/documentation/latest/monitoring_tracing.html#tracing> to level ALL and look at the tracing output (logs, response headers) to see how MBW selection was done. That may give you a clue why your writer was not selected.

HTH,
Marek

> On 18 Feb 2015, at 10:27, Shaswat <shaswat.dasgupta_at_gmail.com> wrote:
>
>
>
> We have a custom MessageBodyWriter in our application that produces data of
> Media type application/xml.As we know Jersey 2.x has an
> algorithm(https://jersey.java.net/documentation/latest/message-body-workers.html#mbw.writer.selection.algorithm)
> that chooses a suitable MBR from a list of internal and custom
> MessageBodyWriters to persist entity into output buffer.The algorithm sorts
> MBR is based upon Object type distance and media type distance.So our Custom
> MBR is not getting invoked as we saw in the Jersey common code
> (MessageBodyFactory.getMessageBodyWriter())that our Custom Writer is at the
> below in the list and some other provider whose isWriteable() method returns
> true getting invoked.
>
> The question is how can we force Jersey to invoke custom MessageBodyWriters
> ??Should we try adding a custom media type(like application/vnd.xml) to
> force it to call Custom types?
>
>
>
>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/Jersey-2-10-4-Entity-provider-selection-algorithm-gives-less-priority-to-custom-providers-MessageBodd-tp7583127.html
> Sent from the Jersey mailing list archive at Nabble.com.