Class JsonValuePropertyEvaluator


  • public final class JsonValuePropertyEvaluator
    extends Object
    A utility that traverses a JsonValue and does property substitution as well as type coercion.
    • Constructor Detail

      • JsonValuePropertyEvaluator

        public JsonValuePropertyEvaluator​(SubstitutionService substitutionService,
                                          List<JsonValuePropertyEvaluator.CoercionFunctionSpec> coercionFunctions)
        Constructs a JsonValuePropertyEvaluator which traverses a JsonValue and 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 functions
        substitutionService - The SubstitutionService to use to do property substitution.
    • Method Detail

      • 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.