users@jax-rs-spec.java.net

[jax-rs-spec users] Re: Different algorithms for sorting MBRs and MBWs

From: Santiago Pericas-Geertsen <Santiago.PericasGeertsen_at_oracle.com>
Date: Thu, 26 Mar 2015 09:01:55 -0400

Hi Sergey,

> Sort the selected MessageBodyWriter providers with a primary key of generic type where providers whose generic type is the nearest superclass of the object class are sorted first and a secondary key of
> media type (see Section 4.2.3).
>
> and for MBRs:
>
> Select the set of MessageBodyReader classes that support the media type of the request, see Section 4.2.3.
>
>
> Why the MBR text does not refer to the Java parameter type as a primary key for sorting the providers, with the media type being the secondary keys.

 Of course MBRs do take into account the Java type, but there is no sorting as you point out.

 Suppose B extends A. If your resource parameter is of type B, there’s no point in using a MBR that can only produce A, you really need a B. On the other hand, if your method returns B, you may be able to use a MBW for A if one for B does not exist —it will at least serialize a part of the object.

 By the same token, you could argue that if C extends B, then you could use a MBR for C to produce a B. So for readers you could use subtypes instead of supertypes. I don’t know the history if this, but I suppose readers were assumed to be strict (needing to deserialize complete objects) while writers were not.

— Santiago