in src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java [1033:1063]
private Result<Object> adaptIfNecessary(final Object value, final Class<?> type, final Type genericType) {
final Object adaptedValue;
if (!isAcceptableType(type, genericType, value)) {
if (genericType instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) genericType;
if (value instanceof Collection &&
(type.equals(Collection.class) || type.equals(List.class)) &&
parameterizedType.getActualTypeArguments().length == 1) {
List<Object> result = new ArrayList<>();
for (Object valueObject : (Collection<?>) value) {
Result<Object> singleValueResult = adapt(valueObject, (Class<?>) parameterizedType.getActualTypeArguments()[0], true);
if (singleValueResult.wasSuccessful()) {
result.add(singleValueResult.getValue());
} else {
return singleValueResult;
}
}
adaptedValue = result;
} else {
return new Result<>(new ModelClassException(String.format("%s is neither a parameterized Collection or List",
type)));
}
} else {
return adapt(value, type, false);
}
return new Result<>(adaptedValue);
} else {
return new Result<>(value);
}
}