31
31
public class UnionTypeValidator extends BaseJsonValidator implements JsonValidator {
32
32
private static final Logger logger = LoggerFactory .getLogger (UnionTypeValidator .class );
33
33
34
- private final List <JsonValidator > schemas = new ArrayList <>() ;
34
+ private final List <JsonValidator > schemas ;
35
35
private final String error ;
36
36
37
37
public UnionTypeValidator (SchemaLocation schemaLocation , JsonNodePath evaluationPath , JsonNode schemaNode , JsonSchema parentSchema , ValidationContext validationContext ) {
@@ -41,21 +41,24 @@ public UnionTypeValidator(SchemaLocation schemaLocation, JsonNodePath evaluation
41
41
String sep = "" ;
42
42
errorBuilder .append ('[' );
43
43
44
- if (!schemaNode .isArray ())
44
+ if (!schemaNode .isArray ()) {
45
45
throw new JsonSchemaException ("Expected array for type property on Union Type Definition." );
46
+ }
46
47
47
48
int i = 0 ;
49
+ this .schemas = new ArrayList <>(schemaNode .size ());
48
50
for (JsonNode n : schemaNode ) {
49
51
JsonType t = TypeFactory .getSchemaNodeType (n );
50
52
errorBuilder .append (sep ).append (t );
51
53
sep = ", " ;
52
54
53
- if (n .isObject ())
55
+ if (n .isObject ()) {
54
56
schemas .add (validationContext .newSchema (schemaLocation .append (ValidatorTypeCode .TYPE .getValue ()),
55
57
evaluationPath .append (ValidatorTypeCode .TRUE .getValue ()), n , parentSchema ));
56
- else
57
- schemas .add (new TypeValidator (schemaLocation .append (i ), evaluationPath .append (i ), n , parentSchema , validationContext ));
58
-
58
+ } else {
59
+ schemas .add (new TypeValidator (schemaLocation .append (i ), evaluationPath .append (i ), n , parentSchema ,
60
+ validationContext ));
61
+ }
59
62
i ++;
60
63
}
61
64
0 commit comments