Skip to content

Conversation

@felipestanzani
Copy link
Collaborator

@felipestanzani felipestanzani commented Oct 30, 2025

Summary

This PR introduces convenience overloads to encode plain JSON strings directly to TOON, updates documentation with examples, centralizes JSON parsing, and adds tests. Version is bumped to 0.1.1.

Motivation

  • Simplify workflows where inputs are already JSON (strings), avoiding callers needing to parse into JsonNode first.
  • Keep parsing concerns out of JToon by delegating to a centralized utility.

Changes

  • Added:
    • JToon.encodeJson(String json): String
    • JToon.encodeJson(String json, EncodeOptions options): String
    • Centralized parsing: JsonNormalizer.parse(String) with consistent validation and error handling.
    • Unit tests covering:
      • Objects, primitive arrays, tabular arrays
      • Custom EncodeOptions (indent, delimiter, lengthMarker)
      • Error cases (blank/invalid JSON)
    • README examples for encodeJson, including Java text block usage.
    • Changelog for 0.1.1.
  • Updated:
    • README API section to document new overloads.
    • Version: 0.1.1.

API

  • New methods in JToon:
    • encodeJson(String json)
    • encodeJson(String json, EncodeOptions options)
  • Internally delegates parsing to JsonNormalizer.parse(String) and encoding to ValueEncoder.encodeValue(...).

Behavior and Validation

  • Blank or invalid JSON results in IllegalArgumentException from JsonNormalizer.parse(String).
  • Output format remains identical to encode(...) of equivalent structures.

Breaking Changes

  • None. Purely additive.

Documentation

  • README:
    • Adds Encode a plain JSON string example and explains delimiter options and length markers in context.
    • API list now includes both encodeJson overloads.
  • CHANGELOG:
    • Adds 0.1.1 entry detailing new APIs, docs, and tests.

Testing

  • New tests validate:
    • Encoding JSON objects, primitive arrays, and tabular arrays via string inputs.
    • Custom delimiter and length marker options.
    • Error handling for invalid/blank JSON.
  • Test reports are present under build/reports/tests/test.

Versioning

  • Bumps to 0.1.1 as per CHANGELOG. Artifacts and README badges remain consistent with release automation.

Migration Guide

  • For existing JSON-string-based callers:
    • Replace manual parsing + encode(JsonNode) with the new entry points:
// Before
JsonNode node = objectMapper.readTree(jsonString);
String toon = JToon.encode(node);

// After
String toon = JToon.encodeJson(jsonString);
  • For custom options:
String toon = JToon.encodeJson(jsonString, new EncodeOptions(2, Delimiter.PIPE, true));

Checklist

  • API additions documented in README
  • CHANGELOG updated to 0.1.1
  • Tests added and passing
  • No breaking changes introduced

Summary by CodeRabbit

  • New Features

    • Added encodeJson() methods to encode JSON strings directly to TOON format with optional encoding options and input validation.
  • Documentation

    • Added CHANGELOG tracking version history and release notes.
    • Updated README with new API documentation and usage examples.
  • Tests

    • Added unit tests covering JSON string encoding scenarios and error handling.

- Introduced `JToon.encodeJson(String)` and `JToon.encodeJson(String, EncodeOptions)` methods for direct JSON string encoding to TOON format.
- Centralized JSON parsing in `JsonNormalizer.parse(String)` to maintain separation of concerns.
- Expanded README documentation to include new encoding methods and examples.
- Added a comprehensive changelog to document notable changes and version history.
- Implemented unit tests for JSON string encoding, covering various scenarios and error cases.
@coderabbitai
Copy link

coderabbitai bot commented Oct 30, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces a new JSON string encoding pathway to JToon. It adds encodeJson() method overloads for direct JSON string-to-TOON conversion, centralizes JSON parsing via JsonNormalizer.parse(), includes comprehensive unit tests, and updates CHANGELOG and README documentation accordingly.

Changes

Cohort / File(s) Summary
Documentation
CHANGELOG.md, README.md
CHANGELOG.md created documenting versions 0.1.1 and 0.1.0 with semantic versioning. README.md updated to reflect new encodeJson API methods replacing previous encode methods, includes JSON string encoding examples and Changelog reference.
Core Implementation
src/main/java/com/felipestanzani/jtoon/JToon.java, src/main/java/com/felipestanzani/jtoon/normalizer/JsonNormalizer.java
JToon.java adds two new public static encodeJson() overloads: one delegating to the other with default options, enabling direct JSON string encoding. JsonNormalizer.java adds parse(String json) public static method for centralized JSON parsing with blank validation and exception handling.
Unit Tests
src/test/java/com/felipestanzani/jtoon/JToonJsonStringTest.java
New JUnit 5 test file covering happy paths (simple objects, primitive arrays, tabular arrays, custom options) and error cases (invalid and blank JSON input), verifying IllegalArgumentException thrown appropriately.

Sequence Diagram

sequenceDiagram
    actor User
    participant JToon
    participant JsonNormalizer
    participant MAPPER as ObjectMapper
    participant ValueEncoder
    
    User->>JToon: encodeJson(String json)
    JToon->>JToon: encodeJson(json, DEFAULT_OPTIONS)
    JToon->>JsonNormalizer: parse(json)
    JsonNormalizer->>JsonNormalizer: validate non-blank
    JsonNormalizer->>MAPPER: readTree(json)
    MAPPER-->>JsonNormalizer: JsonNode
    JsonNormalizer-->>JToon: JsonNode
    JToon->>ValueEncoder: encodeValue(JsonNode, options)
    ValueEncoder-->>JToon: TOON String
    JToon-->>User: TOON String
    
    Note over JsonNormalizer: Blank/Invalid JSON<br/>throws IllegalArgumentException
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Multiple cohesive changes across documentation, implementation, and tests
  • New public API methods (encodeJson overloads) require verification of delegation logic and integration with JsonNormalizer.parse()
  • JsonNormalizer.parse() adds new validation and exception-handling logic—verify exception messages and blank input handling
  • Test coverage is comprehensive; verify assertions match expected TOON output formats and edge cases
  • Cross-check README API documentation alignment with actual method signatures

Poem

🐰 Hop, hop! A JSON string arrives,
No middleman needed—straight through we dive!
Parse, normalize, encode with care,
TOON format blooms in the autumn air! 🍂

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch plainJson

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d58ddc9 and fb5b1be.

📒 Files selected for processing (5)
  • CHANGELOG.md (1 hunks)
  • README.md (4 hunks)
  • src/main/java/com/felipestanzani/jtoon/JToon.java (2 hunks)
  • src/main/java/com/felipestanzani/jtoon/normalizer/JsonNormalizer.java (1 hunks)
  • src/test/java/com/felipestanzani/jtoon/JToonJsonStringTest.java (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@felipestanzani felipestanzani merged commit 58c7eb7 into main Oct 30, 2025
1 of 2 checks passed
@felipestanzani felipestanzani deleted the plainJson branch November 6, 2025 18:36
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.

2 participants