users@jax-rs-spec.java.net

[jax-rs-spec users] Re: Use "extensible enums" for HTTP codes, Mediatypes, Headers, Link Relation?

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Wed, 21 Mar 2012 22:56:44 +0100

Thanks for the tip. We are already doing this for response status codes. We can certainly look into Link rels, as those are new. I'll have to check about headers and media types, since we need to make sure to not break the BW compatibility.

Thanks,
Marek
On Mar 16, 2012, at 10:42 AM, Thomas Koch wrote:

> Another thought.
>
> Bloch describes how to use enums and still have the possibility to kind of
> "extend them" in Effective Java ed2 item 34. The trick is to have the enum
> implement an interface and to refer to the interface instead of the enum type.
>
> There are plenty of constants lists in JAX-RS. Have you considered using such
> "extensible enums" instead, e.g. for HTTP codes, Mediatypes, Header names,
> Link relations, HTTP methods?
>
> There's already a type for MediaType. I think it would be nice to have types
> for the other entities too. I'd especially like them for HTTPCode and
> HTTPMethod to refer to them for dependency injection.
>
> The provider method of my Preconditions interface from my earlier email for
> example requires the HTTPMethod but currently needs to take it from the
> Request class.
>
> Best regards,
>
> Thomas Koch, http://www.koch.ro