mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-11 05:41:52 +01:00
Allow String values for other Types (#2699)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
parent
fd16210ee6
commit
16bc9321f1
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
// ===========================================================================
|
||||
|
Loading…
Reference in New Issue
Block a user