commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oliver Heger (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CONFIGURATION-508) Add generic get method to convert config property to any object
Date Mon, 05 Aug 2013 20:04:48 GMT

    [ https://issues.apache.org/jira/browse/CONFIGURATION-508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13729881#comment-13729881
] 

Oliver Heger commented on CONFIGURATION-508:
--------------------------------------------

It is planned for version 2.0 to make the conversion facilities more flexible and customizable.
In this course, we can also add generic get() methods to the Configuration interface.

I am going to start working on this topic right now.
                
> Add generic get method to convert config property to any object
> ---------------------------------------------------------------
>
>                 Key: CONFIGURATION-508
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-508
>             Project: Commons Configuration
>          Issue Type: Improvement
>          Components: Type conversion
>    Affects Versions: 1.9
>            Reporter: Matt Bertolini
>              Labels: configuration, constructor, conversion, convert, generic, property,
static, type, valueof
>
> Now that commons configuration requires java 5.0+, I think we should consider adding
a couple of new generic getter methods that will enable developers to automatically convert
the configuration property to the object of their choice. I envision the API looking like
the below:
> {code:java}
> public <T> T get(String key, Class<T> clazz);
> public <T> T get(String key, Class<T> clazz, T defaultValue);
> {code}
> The method would perform a five step process:
> # First it would get the string value, post interpolation.
> # Then it would check the given class for the existence of a static "valueOf" method
with one String argument. If found, it would invoke that method with the interpolated string
value.
> # If no static "valueOf" method is found, it would search for a constructor with one
String argument. If that is found, it would construct a new instance of the class passing
the interpolated string value.
> # If no constructor or static method is found, it will check if a default value was given,
returning it if true.
> # Finally, if no default value is given, it checks to see if throwExceptionOnMissing
is set to true. If so, it will throw the exception. If false, it will return null.
> This behavior is similar to how the Spring conversion service works. I believe that this
feature would be a great help to developers as many of the values contained in configuration
properties often times map over to various model objects.
> I am looking for some feedback on the idea. Let me know your thoughts. Thanks.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message