in streams-config/src/main/java/org/apache/streams/config/StreamsConfigurator.java [149:209]
public T detectCustomConfiguration(Config rootConfig, String path) {
Config subConfig = null;
if( StringUtils.isNotBlank(path) && rootConfig.hasPath(path) ) {
subConfig = rootConfig.getConfig(path);
} else {
subConfig = rootConfig;
}
// for each field of the top-level configuration,
// populate using a ComponentConfigurator from its type.
ComponentConfigurator<StreamsConfiguration> streamsConfigConfigurator = new ComponentConfigurator(configClass);
StreamsConfiguration streamsConfiguration = streamsConfigConfigurator.detectConfiguration();
Map<String, Object> pojoMap = new HashMap<>();
try {
pojoMap.putAll(mapper.convertValue(streamsConfiguration, Map.class));
pojoMap.putAll(mapper.readValue(subConfig.resolve().root().render(ConfigRenderOptions.concise()), Map.class));
} catch (Exception e) {
e.printStackTrace();
LOGGER.warn("Could not parse:", subConfig);
}
Field[] fields = configClass.getDeclaredFields();
for( Field field : fields ) {
Class type = field.getType();
if( type != String.class && !ClassUtils.isPrimitiveOrWrapper(type) ) {
ComponentConfigurator configurator = new ComponentConfigurator(type);
try {
Serializable rootValue = configurator.detectConfiguration(rootConfig, field.getName());
if (rootValue != null) {
pojoMap.put(field.getName(), rootValue);
}
} catch( Exception e ) {
// we swallow any parsing problems that happen at this level
}
try {
Serializable pathValue = configurator.detectConfiguration(subConfig, field.getName());
if (pathValue != null) {
pojoMap.put(field.getName(), pathValue);
}
} catch( Exception e ) {
// we swallow any parsing problems that happen at this level
}
}
}
T pojoConfig = null;
try {
pojoConfig = mapper.convertValue(pojoMap, configClass);
} catch (Exception e) {
e.printStackTrace();
LOGGER.warn("Could not parse:", rootConfig);
}
return pojoConfig;
}