code: MessageML parse(String message, String entityJson, String version) throws InvalidInputException, ProcessingException,
        IOException {
      this.index = 0;
      String expandedMessage;
  
      if (StringUtils.isBlank(message)) {
       throw new InvalidInputException("Error parsing message: the message cannot be null or empty");
      }
  
      if (StringUtils.isNotBlank(entityJson)) {
        try {
          this.entityJson = (ObjectNode) MAPPER.readTree(entityJson);
        } catch (JsonProcessingException e) {
          throw new InvalidInputException("Error parsing EntityJSON: " + e.getMessage());
        }
      } else {
        this.entityJson = new ObjectNode(JsonNodeFactory.instance);
      }
  
      try {
        expandedMessage = expandTemplates(message, this.entityJson);
      } catch (IOException e) {
        throw new InvalidInputException("Error parsing EntityJSON: " + e.getMessage());
      } catch (TemplateException e) {
        throw new InvalidInputException(String.format("Error parsing Freemarker template: invalid input at line %s, "
            + "column %s", e.getLineNumber(), e.getColumnNumber()));
      }
  
      this.messageML = parseMessageML(expandedMessage, version);
  
      if (this.messageML != null) {
        this.entityJson = this.messageML.asEntityJson(this.entityJson);
  
        return this.messageML;
      }
  
      throw new ProcessingException("Internal error. Generated null MessageML from valid input");
    }
docs: Parse the text contents of the message and optionally EntityJSON into a MessageMLV2 message. Expands
  Freemarker templates and generates a MessageML document tree.
  @param message string containing a MessageMLV2 message with optional Freemarker templates
  @param entityJson string containing EntityJSON data
  @param version string containing the version of the message format
  @throws InvalidInputException thrown on invalid MessageMLV2 input
  @throws ProcessingException thrown on errors generating the document tree
  @throws IOException thrown on invalid EntityJSON input