Class MarkdownParserSession

All Implemented Interfaces:
BeanSession, ConverterSession, RecordReadable
Direct Known Subclasses:
MarkdownDocParserSession

Session object for MarkdownParser.

Parses Markdown tables and bulleted lists into Java objects.

Notes:
  • This class is not thread safe and is typically discarded after one use.
  • Constructor Details

  • Method Details

    • create

      Creates a new builder for this object.
      Parameters:
      ctx - The context creating this session.
      Cannot be null.
      Returns:
      A new builder.
    • readRecords

      public RecordReader readRecords(Object input) throws IOException
      Description copied from interface: RecordReadable
      Opens a low-level RecordReader cursor over the specified input.

      When invoked on a convenience Parser the cursor is opened with default session args (mirroring read(...)). Callers that need request-derived configuration (locale, timezone, schema, swaps) should instead call createSession(args).build() and invoke this method on the resulting ParserSession (which is also a RecordReadable).

      Specified by:
      readRecords in interface RecordReadable
      Parameters:
      input - The input. Subtypes define the supported types (typically Reader / CharSequence / InputStream / byte[] / File).
      Returns:
      A new RecordReader cursor.
      Throws:
      IOException - If a problem occurred reading the underlying input.
    • isRecordStreaming

      public boolean isRecordStreaming()
      Description copied from interface: RecordReadable
      Streaming-quality signal queryable before opening a cursor.
      Specified by:
      isRecordStreaming in interface RecordReadable
      Returns:
      true if RecordReadable.readRecords(Object) returns an O(1)-memory streaming cursor; false for buffered (whole-value) formats backed by RecordAdapter.
    • doRead

      protected <T> T doRead(ParserPipe pipe, ClassMeta<T> type) throws IOException, ParseException
      Description copied from class: ParserSession
      Workhorse method.

      Subclasses are expected to implement this method or Parser.doRead(ParserSession,ParserPipe,ClassMeta).

      The default implementation of this method simply calls Parser.doRead(ParserSession,ParserPipe,ClassMeta).

      Overrides:
      doRead in class ParserSession
      Type Parameters:
      T - The class type of the object to create.
      Parameters:
      pipe - Where to get the input from.
      type - The class type of the object to create. If null or Object.class, object type is based on what's being parsed. For example, when parsing JSON text, it may return a String, Number, JsonMap, etc...
      Returns:
      The parsed object.
      Throws:
      IOException - Thrown by underlying stream.
      ParseException - Malformed input encountered.
    • readAnything

      protected <T> T readAnything(List<String> lines, ClassMeta<T> eType, Object outer, BeanPropertyMeta pMeta) throws IOException, ParseException
      Main parse dispatch method.
      Type Parameters:
      T - The target type.
      Parameters:
      lines - All input lines.
      eType - The expected type.
      outer - The outer object (for inner class instantiation).
      pMeta - The parent bean property meta (may be null).
      Returns:
      The parsed object.
      Throws:
      IOException - Thrown by underlying stream.
      ParseException - If parsing fails.
    • readTable

      protected Object readTable(List<String> lines, ClassMeta<?> eType, Object outer) throws ParseException
      Parses a Markdown table (either 2-column key/value or multi-column).
      Parameters:
      lines - All input lines.
      eType - The expected type.
      outer - The outer object.
      Returns:
      The parsed object.
      Throws:
      ParseException - If parsing fails.
    • readKeyValueTable

      protected Object readKeyValueTable(List<String> headers, List<String> dataLines, ClassMeta<?> eType, Object outer) throws ParseException
      Parses a 2-column key/value Markdown table.
      Parameters:
      headers - The header names.
      dataLines - The data row lines.
      eType - The expected type.
      outer - The outer object.
      Returns:
      The parsed bean, map, or other object.
      Throws:
      ParseException - If parsing fails.
    • readMultiColumnTable

      protected Object readMultiColumnTable(List<String> headers, List<String> dataLines, ClassMeta<?> eType, Object outer) throws ParseException
      Parses a multi-column Markdown table (N columns).
      Parameters:
      headers - The column header names.
      dataLines - The data row lines.
      eType - The expected type.
      outer - The outer object.
      Returns:
      The parsed list of beans, maps, or other objects.
      Throws:
      ParseException - If parsing fails.
    • readRow

      protected Object readRow(List<String> headers, List<String> cells, ClassMeta<?> eType, Object outer) throws ParseException
      Parses a single data row into the specified element type.
      Parameters:
      headers - The column header names.
      cells - The cell values for this row.
      eType - The element type.
      outer - The outer object.
      Returns:
      The parsed element.
      Throws:
      ParseException - If parsing fails.
    • readBulletList

      protected Object readBulletList(List<String> lines, ClassMeta<?> eType, Object outer) throws ParseException
      Parses a Markdown bulleted list into a collection or array.
      Parameters:
      lines - All input lines.
      eType - The expected type.
      outer - The outer object.
      Returns:
      The parsed collection, array, or single element.
      Throws:
      ParseException - If parsing fails.
    • readCellValue

      protected <T> T readCellValue(String val, ClassMeta<T> eType, Object outer) throws ParseException
      Converts a raw Markdown table cell string to the target type.

      If the cell matches the configured null value, returns null. If the cell is backtick-wrapped JSON5, parses via Json5Parser. Otherwise, attempts numeric/boolean auto-detection when the target type is Object.

      Type Parameters:
      T - The target type.
      Parameters:
      val - The raw cell string (already unescaped).
      eType - The target type.
      outer - The outer object (parent bean) for @ParentProperty support.
      Returns:
      The parsed value.
      Throws:
      ParseException - If parsing fails.
    • splitTableRow

      protected List<String> splitTableRow(String line)
      Splits a Markdown table row into its cell values, stripping leading/trailing whitespace and pipes.
      Parameters:
      line - The raw table row line.
      Returns:
      The list of trimmed cell values.
    • isSeparatorRow

      protected boolean isSeparatorRow(String line)
      Returns whether a table row is a separator row (e.g. |---|---|).
      Parameters:
      line - The table row line.
      Returns:
      Whether it is a separator row.
    • readAllLines

      Reads all lines from the given reader.
      Parameters:
      r - The reader.
      Must not be null.
      Returns:
      All lines.
      Throws:
      IOException - Thrown by underlying stream.
    • unescapeCell

      protected String unescapeCell(String s)
      Unescapes Markdown table cell escape sequences.
      Parameters:
      s - The escaped cell value.
      Can be null (returns null).
      Returns:
      The unescaped value. Returns null if the input was null.