|
@@ -1,8 +1,9 @@
|
|
|
package org.leumasjaffe.json.schema.tester;
|
|
package org.leumasjaffe.json.schema.tester;
|
|
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
+import org.leumasjaffe.container.EitherStream;
|
|
|
import org.leumasjaffe.json.JsonHelper;
|
|
import org.leumasjaffe.json.JsonHelper;
|
|
|
import org.leumasjaffe.json.schema.Tester;
|
|
import org.leumasjaffe.json.schema.Tester;
|
|
|
import org.leumasjaffe.json.schema.ValidationException;
|
|
import org.leumasjaffe.json.schema.ValidationException;
|
|
@@ -21,14 +22,10 @@ public class PropertyNameTester implements Tester {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void validate(JsonNode node) throws ValidationException {
|
|
public void validate(JsonNode node) throws ValidationException {
|
|
|
- final List<ValidationException> exceptions = new ArrayList<>();
|
|
|
|
|
- node.fieldNames().forEachRemaining(name -> {
|
|
|
|
|
- try {
|
|
|
|
|
- schema.validate(TextNode.valueOf(name));
|
|
|
|
|
- } catch (ValidationException ve) {
|
|
|
|
|
- exceptions.add(ve);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ final List<ValidationException> exceptions =
|
|
|
|
|
+ EitherStream.from(JsonHelper.fieldNames(node, TextNode::valueOf))
|
|
|
|
|
+ .map(schema::validate, ValidationException.class)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
if (!exceptions.isEmpty()) {
|
|
if (!exceptions.isEmpty()) {
|
|
|
throw new ValidationException("propertyNames", "unable to match property names",
|
|
throw new ValidationException("propertyNames", "unable to match property names",
|
|
|
exceptions);
|
|
exceptions);
|