Problems problems,
SchemaDocumentResolver resolver ) {
if (fieldValue instanceof List) {
// Each item in the list must match the itemValidator or additionalItemsValidator ...
List<?> items = (List<?>)fieldValue;
Path path = pathToParent.with(fieldName);
int i = 1;
boolean success = true;
for (Object item : items) {
itemProblems.clear();
itemValidator.validate(item, fieldName, parent, pathToParent, itemProblems, resolver);
if (itemProblems.hasProblem()) {
problems.recordError(path, "The '" + fieldName + "' field on '" + pathToParent
+ "' is an array, but the " + i + th(i)
+ " item does not satisfy the schema for the " + i + th(i) + " item");
success = false;
}
++i;
}
if (success) problems.recordSuccess();
} else if (parent instanceof List) {
// we are dealing with an optional array of items
List<?> items = (List<?>)parent;
int i = 1;
boolean success = true;
for (Object item : items) {
itemProblems.clear();
if (item instanceof Document) {
itemValidator.validate(null, null, (Document)item, pathToParent, itemProblems, resolver);
if (itemProblems.hasProblem()) {
success = false;
}
} else {
fieldName = item.toString();
Path path = pathToParent.with(fieldName);
itemValidator.validate(item, fieldName, parent, pathToParent, itemProblems, resolver);
if (itemProblems.hasProblem()) {
problems.recordError(path, "The '" + fieldName + "' field on '" + pathToParent
+ "' is an array, but the " + i + th(i)
+ " item does not satisfy the schema for the " + i + th(i) + " item");