Allow String values for other Types (#2699)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
Christoph Weitkamp 2022-01-29 14:01:16 +01:00 committed by GitHub
parent fd16210ee6
commit 16bc9321f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -123,7 +123,18 @@ final class TypeIntrospections {
* @return true, if the given value can be assigned to the type of this introspection, otherwise false
*/
boolean isAssignable(Object value) {
return clazz.isAssignableFrom(value.getClass());
return clazz.isAssignableFrom(value.getClass()) || isStringInstance(value);
}
/**
* Returns true, if the given value is a string, otherwise false.
*
* @param value the value to be analyzed
*
* @return true, if the given value is a string, otherwise false
*/
final boolean isStringInstance(Object value) {
return value instanceof String;
}
/**

View File

@ -44,6 +44,8 @@ import org.openhab.core.config.core.validation.ConfigValidationException;
import org.openhab.core.config.core.validation.ConfigValidationMessage;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Testing the {@link ConfigDescriptionValidator}.
@ -53,6 +55,8 @@ import org.osgi.framework.BundleContext;
*/
public class ConfigDescriptionValidatorTest {
private final Logger logger = LoggerFactory.getLogger(ConfigDescriptionValidatorTest.class);
private static final int MIN_VIOLATED = 1;
private static final int MAX_VIOLATED = 1234;
@ -190,6 +194,14 @@ public class ConfigDescriptionValidatorTest {
configDescriptionValidator.validate(params, CONFIG_DESCRIPTION_URI);
}
@Test
public void assertValidationThrowsNoExceptionForValidStringConfigParameters() {
params.put(BOOL_PARAM_NAME, "true");
params.put(INT_PARAM_NAME, "1");
params.put(DECIMAL_PARAM_NAME, "1.0");
configDescriptionValidator.validate(params, CONFIG_DESCRIPTION_URI);
}
// ===========================================================================
// REQUIRED VALIDATIONS
// ===========================================================================