KEYCLOAK-12689 - Improvements for camelCase config properties

This commit is contained in:
Dmitry Telegin 2020-01-15 15:12:16 +03:00 committed by Stian Thorgersen
parent b7b78c87ca
commit e6b4685659

View file

@ -104,10 +104,31 @@ public class MicroProfileConfigProvider implements Config.ConfigProvider {
}
private <T> T getValue(String key, Class<T> clazz, T defaultValue) {
T value = config.getOptionalValue(prefix + "." + key, clazz).orElse(defaultValue);
return value;
String property = prefix + "." + key;
return config.getOptionalValue(toDashCase(property), clazz)
.orElseGet(() -> config.getOptionalValue(property, clazz)
.orElse(defaultValue));
}
}
private static String toDashCase(String s) {
StringBuilder sb = new StringBuilder(s.length());
boolean l = false;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (l && Character.isUpperCase(c)) {
sb.append('-');
c = Character.toLowerCase(c);
l = false;
} else {
l = Character.isLowerCase(c);
}
sb.append(c);
}
return sb.toString();
}
}