Skip to content

Commit

Permalink
Load schema in constructor to avoid reload on each validation (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteeg committed Feb 2, 2023
1 parent 9efce49 commit 8b7ad59
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public final class JsonValidator extends DefaultObjectPipe<String, ObjectReceive

private static final Logger LOG = LoggerFactory.getLogger(JsonValidator.class);
private static final String DEFAULT_ID_KEY = "id";
private String schemaUrl;
private Schema schema;
private long fail;
private long success;
Expand All @@ -67,7 +66,7 @@ public final class JsonValidator extends DefaultObjectPipe<String, ObjectReceive
* @param url The URL of the schema to validate against.
*/
public JsonValidator(final String url) {
this.schemaUrl = url;
initSchema(url);
}

/**
Expand Down Expand Up @@ -103,7 +102,6 @@ public void process(final String json) {

private void validate(final String json, final JSONObject object) {
try {
initSchema();
schema.validate(object); // throws ValidationException if invalid
getReceiver().process(json);
++success;
Expand All @@ -122,7 +120,7 @@ protected void onCloseStream() {
super.onCloseStream();
}

private void initSchema() {
private void initSchema(final String schemaUrl) {
if (schema != null) {
return;
}
Expand Down

0 comments on commit 8b7ad59

Please sign in to comment.