Skip to content

Implementing your own rules

Esta Nagy edited this page Jun 1, 2020 · 3 revisions

Each rule has two mandatory parameters and can have additional parameters on top of those at the discretion of the implementation.

The mandatory parameters are:

Name Type
order Integer
jsonPath com.jayway.jsonpath.JsonPath

The interface all the Rules must implement is called JsonRule. If you can't seem to find the rule that fits your needs, you can always implement your own rule by doing the simple steps below.

  1. Create a class implementing the JsonRule interface or feel free to extend AbstractJsonRule for a bit of convenience.
  2. Define a constructor with the following parameter list: ( FunctionRegistry, RawJsonRule )
  3. Annotate it with @NamedRule adding a unique name for your rule.
  4. In your constructor, figure out how to convert the input parameters you need.
  5. Implement the abstract methods coming form the interface/super class.
  6. Register your rule using JsonRuleRegistry#registerRuleClass(Class)
  7. Yippee-Ki-Yay you made it! You can start using your new rule.