Class Json5lSerializer

All Implemented Interfaces:
Function<Object,String>, ThrowingFunction<Object,String>, JsonMetaProvider, ArrayRecordWritable, RecordWritable, TokenWritable

public class Json5lSerializer extends JsonlSerializer
Serializes POJO models to JSON5L (JSON5 Lines).
Media types

Handles Accept types: application/json5l, application/json5lines, text/json5l

Produces Content-Type types: application/json5l

Description

JSON5L combines the relaxed JSON5 dialect with JSONL's newline-delimited framing: each top-level value is written as a compact document on its own line, exactly as JsonlSerializer does.

By default the per-line output is strict RFC-8259 JSON (byte-identical to JsonlSerializer), keeping output maximally portable. The json5Sugar() opt-in switches the per-line output to JSON5 sugar (single-quoted strings, unquoted field names where safe).

Example:

// Strict-per-line output (default) String json5l = Json5lSerializer.DEFAULT.write(myList); // JSON5-sugar-per-line output Json5lSerializer serializer = Json5lSerializer.create().json5Sugar().build(); String json5l = serializer.write(myList);

Example output, sugar off (List of beans):

{"name":"Alice","age":30} {"name":"Bob","age":25}

Example output, sugar on:

{name:'Alice',age:30} {name:'Bob',age:25}

Notes:
  • This class is thread safe and reusable.
See Also: