PluginRegistry pluginRegistry) {
CodableClassInfo resolvedTypeInfo = new CodableClassInfo(type, pluginRegistry.config(), pluginRegistry);
ConfigObject fieldDefaults = resolvedTypeInfo.getFieldDefaults().root();
for (CodableFieldInfo fieldInfo : resolvedTypeInfo.values()) {
String fieldName = fieldInfo.getName();
ConfigValue fieldValue = root.get(fieldName);
if ((fieldValue == null) && (fieldDefaults.get(fieldName) != null)) {
ConfigValue fieldDefault = fieldDefaults.get(fieldName);
fieldValue = ConfigValueFactory.fromAnyRef(
fieldDefault.unwrapped(), "global default : " + fieldDefault.origin().description());
root = root.withValue(fieldName, fieldValue);
}
if (fieldValue == null) {
continue;
}
if ((fieldInfo.isArray() || fieldInfo.isCollection()) &&
(fieldValue.valueType() != ConfigValueType.LIST)) {
fieldValue = ConfigValueFactory.fromIterable(
Collections.singletonList(fieldValue.unwrapped()), "auto collection of " +
fieldValue.origin().description());
root = root.withValue(fieldName, fieldValue);
}
if (!isCodableType(fieldInfo)) {
continue;
}
if (fieldInfo.isArray() || fieldInfo.isCollection()) {
if (fieldValue.valueType() != ConfigValueType.LIST) {
throw new ConfigException.WrongType(fieldValue.origin(), fieldName,
ConfigValueType.LIST.name(), fieldValue.valueType().name());
}
Class<?> elementType = elementType(fieldInfo);
boolean nested = fieldInfo.isCollectionArray();
fieldValue = expandSugarArray(fieldValue, elementType, pluginRegistry, nested);
} else if (fieldInfo.isMap()) {
if (fieldValue.valueType() != ConfigValueType.OBJECT) {
throw new ConfigException.WrongType(fieldValue.origin(), fieldName,
ConfigValueType.OBJECT.name(), fieldValue.valueType().name());
}
Class<?> elementType = elementType(fieldInfo);
boolean nested = fieldInfo.isMapValueArray();
ConfigObject fieldMap = (ConfigObject) fieldValue;
Map<String, Object> newMap = new HashMap<>(fieldMap.size());
for (Map.Entry<String, ConfigValue> mapEntry : fieldMap.entrySet()) {
ConfigValue mapValue = mapEntry.getValue();
String mapKey = mapEntry.getKey();
ConfigValue resolvedMapObject;
if (nested) {
resolvedMapObject = expandSugarArray(mapValue, elementType, pluginRegistry, false);
} else {
resolvedMapObject = expandSugar(elementType, mapValue, pluginRegistry);
}
newMap.put(mapKey, resolvedMapObject.unwrapped());
}
fieldValue = ConfigValueFactory.fromMap(newMap, fieldMap.origin().description());
} else {
fieldValue = expandSugar(fieldInfo.getTypeOrComponentType(), fieldValue, pluginRegistry);
}