Load external data inside custom validator during validation #1047
-
Hi there, I took a look into the Docs and existing discussions, but didn't find an answer to my question. So I hope someone can help me with that: Currently my implementation looks similar to this code: JsonMetaSchema customMetaSchema = JsonMetaSchema.builder(JsonMetaSchema.getV202012())
.keyword(new CustomKeyword())
.build()
JsonSchemaFactory jsonSchemaFactory = new JsonSchemaFactory.Builder().defaultMetaSchemaIri(customMetaSchema.getIri())
.metaSchema(customMetaSchema)
.build();
JsonSchema jsonSchema = jsonSchemaFactory.getSchema(jsonNode);
ValidationResult validationResult = jsonSchema.validateAndCollect(node); And the Collector would be something like this: public class CustomCollector implements Collector<List<String>> {
private final ExternalService externalService;
public CustomCollector(ExternalService externalService) {
this.externalService = externalService;
}
@Override
public void combine(Object object) {
}
@Override
public List<String> collect() {
return externalService.loadExternalData();
}
} If the collector is the right choice to do this, what is the way of including them into the validation and use the collected data inside a custom validator? TIA |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Not clear what your use case is. What are you going to do with this data? If you want to load data in a validator you would just have a service in your custom validator implementation to load the data. Nothing to do with a collector. |
Beta Was this translation helpful? Give feedback.
You can pass data on a per execution basis through the
ExecutionContext
.The
validate
method in the validator has aexecutionContext
parameter which you can use to get the data.