Class MarkdownSerializer

All Implemented Interfaces:
Function<Object,String>, ThrowingFunction<Object,String>, MarkdownMetaProvider, RecordWritable
Direct Known Subclasses:
MarkdownDocSerializer

Serializes POJO models to Markdown (fragment mode: tables and lists).
Media types

Handles Accept types: text/markdown, text/x-markdown

Produces Content-Type types: text/markdown

Description

The conversion is as follows:

  • Beans and Maps are serialized as 2-column key/value Markdown tables.
  • Collections and arrays of beans/maps with uniform structure are serialized as multi-column Markdown tables.
  • Collections and arrays of simple values are serialized as Markdown bulleted lists.
  • Nested beans and complex values in table cells are serialized as inline JSON5 wrapped in backticks.
  • Null values are rendered as "*null*" (italic) by default.
Example:

// Use the default serializer to serialize a bean String md = MarkdownSerializer.DEFAULT.write(someObject); // Create a custom serializer MarkdownSerializer serializer = MarkdownSerializer.create().nullValue("—").build(); // Serialize a List of beans to a multi-column Markdown table String md = serializer.write(listOfBeans);

Example output (bean):

| Property | Value | |---|---| | name | Alice | | age | 30 |

Limitations:
  • Multi-line string values cannot round-trip; newlines are replaced with <br>.
  • The configured null value string (default: *null*) cannot be stored as a literal string value.
  • This serializer is thread safe and reusable.
See Also: