darkma773r commented on code in PR #181:
URL:
https://github.com/apache/commons-configuration/pull/181#discussion_r874327321
##########
src/main/java/org/apache/commons/configuration2/interpol/ConfigurationInterpolator.java:
##########
@@ -281,13 +301,34 @@ public ConfigurationInterpolator getParentInterpolator() {
* @return the {@code StringSubstitutor} used by this object
*/
private StringSubstitutor initSubstitutor() {
- return new StringSubstitutor(key -> Objects.toString(resolve(key),
null));
+ return new StringSubstitutor(key -> {
+ final Object value = resolve(key);
+ return value != null
+ ? stringConverter.apply(value)
+ : null;
+ });
}
/**
- * Performs interpolation of the passed in value. If the value is of type
String, this method checks whether it contains
- * variables. If so, all variables are replaced by their current values
(if possible). For non string arguments, the
- * value is returned without changes.
+ * Performs interpolation of the passed in value. If the value is of type
{@code String}, this method checks
+ * whether it contains variables. If so, all variables are replaced by
their current values (if possible). For
+ * non string arguments, the value is returned without changes. In the
special case where the value is a string
+ * consisting of a single variable reference, the interpolated variable
value is <em>not</em> converted to a
+ * string before returning, so that callers can access the raw value.
However, if the variable is part of a larger
+ * interpolated string, then the variable value is converted to a string
using the configured
+ * {@link #getStringConverter() string converter}. (See the discussion on
string conversion in the class
+ * documentation for more details.)
+ *
+ * <p><strong>Examples</strong></p>
+ * <p>
+ * For the following examples, assume that the default string conversion
function is in place and that the
+ * variable {@code i} maps to the integer value {@code 42}.
+ * <pre>
+ * interpolator.interpolate(1) -> 1// non-string argument returned
unchanged
Review Comment:
Ha! That is awesome and the exact thing I need here. Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]