Config API, need ability to handle default string value conversion

18 views
Skip to first unread message

sst...@redhat.com

unread,
Jun 3, 2017, 2:18:19 PM6/3/17
to MicroProfile
Regarding this issue, https://github.com/eclipse/microprofile-config/issues/169, a CDI producer method for @ConfigProperty annotated values does not have to the Converters to be able to create the appropriate injection value in the event there is no value in the application Config. In the Weld/Java SE prototype I have created, I have to couple to the Config implementation details to get this information.

I think the simplest and most useful addition to the api would be to provide access to the conversions known to the application Config by adding a method to Config along the lines of:

/**
* Use the {@link Converter}s registered with the config to convert a String value to a target property type.
* @param svalue - the string value representation of the property
* @param propertyType - the desired Java type of the property
* @return the converted value
* @throws TypeNotPresentException if there is no registered Converter
*/
public <T> T convertValue(String svalue, Class<T> propertyType);

What do you think?

sst...@redhat.com

unread,
Jun 3, 2017, 2:39:07 PM6/3/17
to MicroProfile
And/or a method like:

/**
* Use the {@link Converter}s registered with the config to try to convert a String value to a target property type.
 * @param svalue - the string value representation of the property
* @param propertyType - the desired Java type of the property
 * @return the converted value if a matching converter is found, Optional.empty() otherwise
*/
public <T> Optional<T> tryConvertValue(String svalue, Class<T> propertyType);

Emily Jiang

unread,
Jun 4, 2017, 6:28:35 PM6/4/17
to MicroProfile
Scott,

Please continue the discuss on the issue thread (https://github.com/eclipse/microprofile-config/issues/169) instead of cross posting in two places. Please list your use case. At the moment, we don't understand why converting default value is special. It is same as converting config values.

Emily
Reply all
Reply to author
Forward
0 new messages