Class YamlTemplateHelper

java.lang.Object
org.mockserver.templates.engine.helpers.YamlTemplateHelper

public class YamlTemplateHelper extends Object
YAML helpers for templates: convert YAML to JSON and read a field out of a YAML document. Backed by Jackson's YAML dataformat (already on the classpath via YamlToJsonConverter).
  • Constructor Details

    • YamlTemplateHelper

      public YamlTemplateHelper()
  • Method Details

    • toJson

      public String toJson(String yaml)
      Converts a YAML document to its JSON representation. Returns an empty string for null or empty input, and the original input if it cannot be parsed as YAML.
    • parse

      public String parse(String yaml, String fieldName)
      Reads a top-level field from a YAML document and returns its value as a string (scalars are returned verbatim, objects/arrays as JSON). Returns an empty string when the field is absent or the input cannot be parsed.
    • toString

      public String toString()
      Overrides:
      toString in class Object