users@jsr311.java.net

1.1 Change C006

From: Michael Brackx <michael.javaone_at_gmail.com>
Date: Mon, 23 Feb 2009 16:55:14 +0100

Hi,

Instead of requiring a static fromString method for converting
parameters i would suggest the introduction of an extra extension
point: the StringConverter provider.

A StringConverter could do the conversion from(/to) a String to(/form)
a parameter type. It could be annotated with @Provider and be
registered like other providers.

This functionality has been implemented in RESTEasy
The StringConverter javadoc:
http://www.jboss.org/file-access/default/members/resteasy/freezone/docs/1.0.2.GA/javadocs/org/jboss/resteasy/spi/StringConverter.html
Documentation:
http://www.jboss.org/file-access/default/members/resteasy/freezone/docs/1.0.2.GA/userguide/html/StringConverter.html

Some advantages over a static fromString/valueOf method:
- StringConverters can be used if the parameter type cannot be changed:
-- types from third party libraries
-- if code is not available
-- if classes are final
- sometimes static methods are not recommended, for example because
they cannot be stubbed, or even not permitted because of code style
- enum names can be restricted by code style (e.g. all uppercase),
where an API might required lowercase "constants"

Michael Brackx