|
36 | 36 | */
|
37 | 37 | public class JsonSchema extends BaseJsonValidator {
|
38 | 38 | private static final Pattern intPattern = Pattern.compile("^[0-9]+$");
|
39 |
| - protected Map<String, JsonValidator> validators; |
| 39 | + private Map<String, JsonValidator> validators; |
40 | 40 | private final String idKeyword;
|
41 | 41 | private final ValidationContext validationContext;
|
42 | 42 | private WalkListenerRunner keywordWalkListenerRunner;
|
@@ -80,11 +80,6 @@ private JsonSchema(ValidationContext validationContext, String schemaPath, URI c
|
80 | 80 | }
|
81 | 81 | }
|
82 | 82 |
|
83 |
| - JsonSchema initialize() { |
84 |
| - this.validators = Collections.unmodifiableMap(this.read(getSchemaNode())); |
85 |
| - return this; |
86 |
| - } |
87 |
| - |
88 | 83 | private URI combineCurrentUriWithIds(URI currentUri, JsonNode schemaNode) {
|
89 | 84 | final String id = validationContext.resolveSchemaId(schemaNode);
|
90 | 85 | if (id == null) {
|
@@ -225,7 +220,7 @@ private Map<String, JsonValidator> read(JsonNode schemaNode) {
|
225 | 220 |
|
226 | 221 | public Set<ValidationMessage> validate(JsonNode jsonNode, JsonNode rootNode, String at) {
|
227 | 222 | Set<ValidationMessage> errors = new LinkedHashSet<ValidationMessage>();
|
228 |
| - for (JsonValidator v : validators.values()) { |
| 223 | + for (JsonValidator v : getValidators().values()) { |
229 | 224 | errors.addAll(v.validate(jsonNode, rootNode, at));
|
230 | 225 | }
|
231 | 226 | return errors;
|
@@ -296,7 +291,7 @@ public ValidationResult walk(JsonNode node, boolean shouldValidateSchema) {
|
296 | 291 | public Set<ValidationMessage> walk(JsonNode node, JsonNode rootNode, String at, boolean shouldValidateSchema) {
|
297 | 292 | Set<ValidationMessage> validationMessages = new LinkedHashSet<ValidationMessage>();
|
298 | 293 | // Walk through all the JSONWalker's.
|
299 |
| - for (Entry<String, JsonValidator> entry : validators.entrySet()) { |
| 294 | + for (Entry<String, JsonValidator> entry : getValidators().entrySet()) { |
300 | 295 | JsonSchemaWalker jsonWalker = entry.getValue();
|
301 | 296 | String schemaPathWithKeyword = entry.getKey();
|
302 | 297 | try {
|
@@ -343,6 +338,9 @@ public JsonValidator getRequiredValidator() {
|
343 | 338 | }
|
344 | 339 |
|
345 | 340 | public Map<String, JsonValidator> getValidators() {
|
| 341 | + if (validators == null) { |
| 342 | + validators = Collections.unmodifiableMap(this.read(getSchemaNode())); |
| 343 | + } |
346 | 344 | return validators;
|
347 | 345 | }
|
348 | 346 |
|
|
0 commit comments