1818
1919import com .fasterxml .jackson .databind .JsonNode ;
2020import com .fasterxml .jackson .databind .ObjectMapper ;
21+
2122import org .slf4j .Logger ;
2223import org .slf4j .LoggerFactory ;
2324
2425import java .util .ArrayList ;
2526import java .util .HashSet ;
27+ import java .util .Iterator ;
2628import java .util .List ;
2729import java .util .Set ;
28- import java .util .stream .Collectors ;
2930
3031public class OneOfValidator extends BaseJsonValidator implements JsonValidator {
3132 private static final Logger logger = LoggerFactory .getLogger (RequiredValidator .class );
@@ -46,13 +47,13 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
4647 debug (logger , node , rootNode , at );
4748
4849 int numberOfValidSchema = 0 ;
49- Set <ValidationMessage > errors = new HashSet <>();
50+ Set <ValidationMessage > errors = new HashSet <ValidationMessage >();
5051
5152 for (JsonSchema schema : schemas ) {
5253 Set <ValidationMessage > schemaErrors = schema .validate (node , rootNode , at );
5354 if (schemaErrors .isEmpty ()) {
5455 numberOfValidSchema ++;
55- errors = new HashSet <>();
56+ errors = new HashSet <ValidationMessage >();
5657 }
5758 if (numberOfValidSchema == 0 ){
5859 errors .addAll (schemaErrors );
@@ -63,13 +64,17 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
6364 }
6465
6566 if (numberOfValidSchema == 0 ) {
66- errors = errors .stream ()
67- .filter (msg -> !ValidatorTypeCode .ADDITIONAL_PROPERTIES
68- .equals (ValidatorTypeCode .fromValue (msg .getType ())))
69- .collect (Collectors .toSet ());
67+ for (Iterator <ValidationMessage > it = errors .iterator (); it .hasNext ();) {
68+ ValidationMessage msg = it .next ();
69+
70+ if (ValidatorTypeCode .ADDITIONAL_PROPERTIES .equals (ValidatorTypeCode .fromValue (msg
71+ .getType ()))) {
72+ it .remove ();
73+ }
74+ }
7075 }
7176 if (numberOfValidSchema > 1 ) {
72- errors = new HashSet <>();
77+ errors = new HashSet <ValidationMessage >();
7378 errors .add (buildValidationMessage (at , "" ));
7479 }
7580
0 commit comments