String singleKeyName = configObject.keySet().iterator().next();
try {
Class<T> singleKeyType = (Class<T>) pluginMap.getClass(singleKeyName);
CodableClassInfo singleKeyInfo = getOrCreateClassInfo(singleKeyType);
ConfigObject aliasDefaults = pluginMap.aliasDefaults(singleKeyName);
ConfigValue configValue = configObject.get(singleKeyName);
if (configValue.valueType() != ConfigValueType.OBJECT) {
if (aliasDefaults.get("_primary") != null) {
// if value is not an object, try supporting _primary syntax to derive one
configValue = configValue.atPath((String) aliasDefaults.get("_primary").unwrapped()).root();
} else if (ValueCodable.class.isAssignableFrom(singleKeyType)) {
// see if the resolved type is innately okay with non-objects
try {
T objectShell = singleKeyType.newInstance();
Config fieldDefaults = singleKeyInfo.getFieldDefaults();
// do not merge objects between global defaults and user defaults (incl. alias defaults)
ConfigObject mergedDefaults = aliasDefaults;
for (Map.Entry<String, ConfigValue> pair : fieldDefaults.entrySet()) {
if (!mergedDefaults.containsKey(pair.getKey())) {
mergedDefaults = mergedDefaults.withValue(pair.getKey(), pair.getValue());
}
}
((ValueCodable) objectShell).fromConfigValue(configValue, mergedDefaults);
return objectShell;
} catch (InstantiationException | IllegalAccessException | RuntimeException ex) {
throw new ConfigException.BadValue(configValue.origin(), singleKeyType.getName(),
"exception during instantiation of a ValueCodable", ex);
}
} else {
throw new ConfigException.WrongType(configValue.origin(), singleKeyName,
"OBJECT", configValue.valueType().toString());
}
}
ConfigObject fieldValues = ((ConfigObject) configValue).withFallback(aliasDefaults);
return createAndPopulate(singleKeyInfo, singleKeyType, fieldValues);
} catch (ClassNotFoundException ignored) {