Package dev.harrel.jsonschema
Class EvaluatorFactory.Builder
java.lang.Object
dev.harrel.jsonschema.EvaluatorFactory.Builder
- Enclosing interface:
EvaluatorFactory
Builder for constructing
EvaluatorFactory instances which is an alternative for providing a custom implementation.
It is recommended when the Evaluator creation logic is simple and depends only on keyword name.
To create factory which supports only "custom" and "type" keywords, you can write the following code:
new EvaluatorFactory.Builder()
.withKeyword("custom", CustomEvaluator::new)
.withKeyword("type", CustomTypeEvaluator::new)
.build();
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Creates factory instance.withKeyword(String keyword, BiFunction<SchemaParsingContext, JsonNode, Evaluator> evaluatorProvider) Registers an evaluator with a given keyword.withKeyword(String keyword, Function<JsonNode, Evaluator> evaluatorProvider) withKeyword(String keyword, Supplier<Evaluator> evaluatorProvider)
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
withKeyword
public EvaluatorFactory.Builder withKeyword(String keyword, BiFunction<SchemaParsingContext, JsonNode, Evaluator> evaluatorProvider) Registers an evaluator with a given keyword.- Parameters:
keyword- field name in JSON schema objectevaluatorProvider- function that createsEvaluatorinstance. Invoked only during schema parsing process. Can return null or throw an exception, which will cancel the registration process.- Returns:
- this
-
withKeyword
public EvaluatorFactory.Builder withKeyword(String keyword, Function<JsonNode, Evaluator> evaluatorProvider) - See Also:
-
withKeyword
- See Also:
-
build
Creates factory instance.- Returns:
- factory instance
-