Package org.forgerock.config.util
Class JsonValuePropertyEvaluator
java.lang.Object
org.forgerock.config.util.JsonValuePropertyEvaluator
A utility that traverses a
JsonValue and does property substitution as well as type coercion.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe specification for a coercion function.static final classBuilder to create aJsonValuePropertyEvaluator.CoercionFunctionSpec. -
Constructor Summary
ConstructorsConstructorDescriptionJsonValuePropertyEvaluator(SubstitutionService substitutionService, List<JsonValuePropertyEvaluator.CoercionFunctionSpec> coercionFunctions) Constructs a JsonValuePropertyEvaluator which traverses aJsonValueand does property substitution as well as type coercion. -
Method Summary
Modifier and TypeMethodDescriptionDefine a coercion function.Traverses aJsonValueand does property substitution as well as any type coercion.evaluate(JsonValue object, SubstitutionContext context) Traverses aJsonValueand does property substitution as well as any type coercion.inlineCoercionFunction(Path relativeTo) Creates a coercion function that inlines the content of another file that may be a relative path to a current location.singleKeyWithName(String name) Create a predicate for a JSON coercion function as used in theMapargument toJsonValuePropertyEvaluator(SubstitutionService, List).
-
Constructor Details
-
JsonValuePropertyEvaluator
public JsonValuePropertyEvaluator(SubstitutionService substitutionService, List<JsonValuePropertyEvaluator.CoercionFunctionSpec> coercionFunctions) Constructs a JsonValuePropertyEvaluator which traverses aJsonValueand does property substitution as well as type coercion. Custom coercion functions can be added to the additionalCoercionFunctions map. Custom functions should Be a function that takes a value like{ "properties" : { "$yourKey" : "your_object_stringified" } }and transforms it into{ "properties" : your_transformed_object }- Parameters:
coercionFunctions- Any additional type coercion functions in addition to the standard functionssubstitutionService- TheSubstitutionServiceto use to do property substitution.
-
-
Method Details
-
inlineCoercionFunction
public static JsonValuePropertyEvaluator.CoercionFunctionSpec inlineCoercionFunction(Path relativeTo) Creates a coercion function that inlines the content of another file that may be a relative path to a current location.For example, given this content at /tmp/mycontent:
Content that is too large to be written directly into a JSON file. e.g. email template
The this format:{ "attribute" : { "$inline" : "/tmp/mycontent" } }would be converted into this{ "attribute" : "Content that is too large to be\nwritten directly into a JSON file\ne.g. email template" }- Parameters:
relativeTo- The path that the inlined file will be resolved from, if it is not absolute.- Returns:
- A pair of a predicate (that tests to see if this coercion function is referenced by a JSON object) and the coercion function.
-
coerce
public static JsonValuePropertyEvaluator.CoercionFunctionSpecBuilder coerce(Predicate<JsonValue> predicate) Define a coercion function.- Parameters:
predicate- The predicate that will match JSON that can be coerced.- Returns:
- A build to complete the specification.
-
singleKeyWithName
Create a predicate for a JSON coercion function as used in theMapargument toJsonValuePropertyEvaluator(SubstitutionService, List).- Parameters:
name- The name of the coercion function.- Returns:
- A
JsonValuepredicate.
-
evaluate
Traverses aJsonValueand does property substitution as well as any type coercion.- Parameters:
object- TheJsonValueto traverseescape- If true theSubstitutionService.substitute(String, boolean)method will support escaping. If false theSubstitutionService.substitute(String, boolean)method will NOT support escaping- Returns:
- A property substituted and coerced JsonValue
- Throws:
SubstitutionException- when substitution is interrupted because of an error (unresolved var or cycle)
-
evaluate
public JsonValue evaluate(JsonValue object, SubstitutionContext context) throws SubstitutionException Traverses aJsonValueand does property substitution as well as any type coercion.- Parameters:
object- TheJsonValueto traversecontext- TheSubstitutionContextto use when evaluating the properties for substitution- Returns:
- A property substituted and coerced JsonValue
- Throws:
SubstitutionException- when substitution is interrupted because of an error (unresolved var or cycle)
-