Skip to content

Conversation

@peter-lawrey
Copy link
Member

@peter-lawrey peter-lawrey commented Jan 20, 2026

This PR introduces newline-separated JSON Lines support via WireType.JSONL, while keeping the existing comma-separated stream behaviour available via WireType.JSON_ONLY.

WireType.JSONL is intended for streaming/log-style use cases where each message is a complete JSON object on its own line ({...}\n{...}\n). It also adds a JSON-specific reader that can safely consume both JSONL and legacy comma-separated JSON streams.

Motivation

WireType.JSON_ONLY currently emits a comma-separated JSON stream, which is awkward for line-oriented tooling and streaming pipelines. JSONL is a widely used convention that makes record boundaries explicit, supports incremental processing, and plays nicely with “tail -f”, log shippers, and batch ingestion.

What changed

  • New WireType.JSONL

    • Text wire that outputs one JSON document per line (newline terminated).
    • Defaults to no type metadata (useTypes(false)), and uses JSONL-friendly conventions.
  • JSONWire JSONL mode (useJsonlDocuments)

    • Adds a jsonlMode flag to preserve JSONL contexts.

    • Configures JSONL defaults:

      • useTypes(false)
      • useLowerCaseEnums(true) (configurable)
      • JSONL-specific read/write contexts
    • Overrides methodWriter() in JSONL mode to avoid the parent useTextDocuments() call overwriting the JSONL contexts.

  • JSONLReadDocumentContext

    • JSON-specific read context that finds document boundaries by tracking brace/array depth (and respecting JSON strings/escapes), rather than YAML markers.

    • Accepts both:

      • newline-delimited JSONL ({...}\n{...}\n)
      • comma-separated JSON streams ({...},{...},{...})
    • Strips outer braces when presenting the document body to the reader (matching the existing “document wrapper” behaviour).

  • JSONLWriteDocumentContext

    • Ensures each document is a complete JSON object:

      • Wraps output in { ... }
      • Appends \n after each document
    • Produces valid JSONL output for method writer streaming:

      • {"event":[...]}
      • {"event":[...]}
  • Lowercase enum serialisation

    • Adds useLowerCaseEnums(boolean) and implements lowercase output for enums (including untyped enum values) without allocating new strings.

Output format examples

  • Method writer (JSONL)

    {"event":["first",1 ]}
    {"event":["second",2 ]}
    {"event":["third",3 ]}
    
  • Object write note

    • Double braces are expected in some paths because the document context adds outer braces and the reader strips them when exposing content.

Test plan

  • Added/expanded JSONLTest with streaming coverage:

    • testMethodReaderStreamingJsonl – reads multiple newline-delimited events

    • testMethodReaderCommaSeparatedJson – reads comma-separated JSON streams

    • testWriteJsonReadJsonl – verifies WireType.JSON_ONLY output is readable by the JSONL reader

    • testWriteJsonlReadJson – verifies JSONL round-trip

    • Existing JSONL suite: 33 tests pass (1 skipped)

      • mvn -Dtest=JSONLTest test

Compatibility

  • WireType.JSON_ONLY behaviour remains unchanged.
  • WireType.JSONL provides a line-oriented alternative and a reader tolerant of both newline and comma delimiters, easing migration and mixed-stream handling.

@peter-lawrey peter-lawrey changed the base branch from develop to release/2026.XYZ January 20, 2026 12:14
@peter-lawrey peter-lawrey changed the title Feature/jsonl Add WireType.JSONL (JSON Lines) support to Chronicle Wire Jan 20, 2026
- Add JSONLReadDocumentContext for JSON-specific document boundary parsing
  that doesn't rely on YAML-style markers
- Add JSONLWriteDocumentContext to wrap each document in braces and add
  newlines between documents for proper JSONL format
- Add jsonlMode flag to prevent methodWriter() from overwriting JSONL
  contexts when useTextDocuments() is called
- Override methodWriter() in JSONWire to preserve JSONL contexts
- Add tests for method reader streaming with JSONL format
- Add interoperability test showing JSON_ONLY output can be read by JSONL
- Update tests to use readingDocument() for proper document context handling

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@peter-lawrey peter-lawrey changed the title Add WireType.JSONL (JSON Lines) support to Chronicle Wire Add newline-delimited WireType.JSONL (JSON Lines) alongside comma-separated WireType.JSON_ONLY Jan 26, 2026
peter-lawrey and others added 3 commits January 26, 2026 11:48
- Add expected output values for JSONL in WireDumperTest
- Add JSONL to special handling in WireTypeTest.testFromFile like JSON/JSON_ONLY

Co-Authored-By: Claude Opus 4.5 <[email protected]>
…ity; update pom.xml to disable default jar goal
@peter-lawrey peter-lawrey changed the base branch from release/2026.XYZ to develop January 28, 2026 12:54
@sonarqubecloud
Copy link

@peter-lawrey peter-lawrey changed the base branch from develop to feature/tidy January 28, 2026 14:44
Copy link
Contributor

@tgd tgd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well-implemented JSONL support with excellent test coverage. Approving with minor suggestions.

@Override
public void close() {
super.close();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: This empty close() override just calls super.close() and can be removed - it adds no behavior.

* objects, allowing for efficient manipulation and parsing.
*/
@SuppressWarnings("this-escape")
@SuppressWarnings({"this-escape", "deprecation"})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Consider localizing the @SuppressWarnings("deprecation") to the specific method(s) that use deprecated APIs rather than suppressing it class-wide. This makes it clearer which code paths touch deprecated APIs.

* @return this wire configured for JSONL
* @see <a href="https://jsonlines.org/">JSON Lines specification</a>
*/
public JSONWire useJsonlDocuments() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Consider adding a thread-safety note to the Javadoc, e.g.:

 * <p>Thread safety: The returned wire instance is not thread-safe.

This matches the documentation style in the test class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants