Skip to content

Conversation

@felipestanzani
Copy link
Collaborator

Summary

This PR restructures the jtoon package into clearer subpackages, introduces new utilities, significantly expands test coverage, and improves the Gradle build with publishing and verification. It also refactors several core components for readability, maintainability, and performance.

Changes

  • Package structure and refactors:
    • Move Constants to util (src/main/java/com/felipestanzani/jtoon/util/Constants.java).
    • Split encoder logic into encoder package:
      • Add ArrayEncoder, ListItemEncoder, ObjectEncoder, PrimitiveEncoder, TabularArrayEncoder, ValueEncoder, HeaderFormatter, LineWriter (moved).
    • Split normalization into normalizer package:
      • Add JsonNormalizer and package docs.
    • Update JToon.java to align with refactors.
    • Remove old classes that are now relocated or superseded:
      • JsonNormalizer.java (old path), PrimitiveEncoder.java (old path), ValueEncoder.java (old path).
    • Add package-info.java files for jtoon, encoder, normalizer, and util.
  • Utilities:
    • Add StringEscaper and StringValidator under util.
  • Tests:
    • Add tests for new/updated components:
      • HeaderFormatterTest, JsonNormalizerTest, LineWriterTest, PrimitiveEncoderTest, StringEscaperTest, StringValidatorTest.
  • Build and publishing:
    • Update build.gradle.
    • Add gradle/publishing.gradle and gradle/verification.gradle for publishing and verification configurations.
  • Misc:
    • Add .idea/dictionaries/project.xml (note: typically excluded; see Notes).

Commits

  • bcce619 Enhance build configuration and add encoding utilities
  • e271138 Refactor PrimitiveEncoder to enhance clarity and maintainability
  • 3b835b6 Refactor JsonNormalizer to implement a chain of responsibility pattern
  • d5c7cca Refactor JsonNormalizer for improved readability and performance
  • 8775304 Refactor Constants and JToon classes, and add JsonNormalizer unit tests

Motivation

  • Improve code clarity via package organization.
  • Make encoders/normalizers composable and testable.
  • Strengthen input safety and consistency with string utilities.
  • Prepare for publishing and verification via Gradle.

Impact and Compatibility

  • Potentially breaking for consumers importing moved classes:
    • com.felipestanzani.jtoon.Constantscom.felipestanzani.jtoon.util.Constants
    • Encoders moved into com.felipestanzani.jtoon.encoder.*
    • Normalizer moved into com.felipestanzani.jtoon.normalizer.*
  • No behavior changes intended except improved normalization pipeline and clearer encoder responsibilities.

Migration Guide

  • Update imports:
    • Constantscom.felipestanzani.jtoon.util.Constants
    • Encoder classes → com.felipestanzani.jtoon.encoder.*
    • JsonNormalizercom.felipestanzani.jtoon.normalizer.JsonNormalizer
  • If using internal LineWriter, use com.felipestanzani.jtoon.encoder.LineWriter.
  • Consider adopting StringEscaper and StringValidator from util where applicable.

Testing

  • New tests verify header formatting, line writing, primitive encoding, normalization behavior, and utility correctness.
  • All newly added tests pass locally; build produces JAR and javadoc artifacts.

CI/CD and Publishing

  • publishing.gradle configures artifact publishing.
  • verification.gradle configures additional verification tasks.
  • Ensure CI includes check, test, and publishing dry-runs as needed.

Documentation

  • package-info.java added across key packages to clarify responsibilities.
  • Javadoc generated under build/docs/javadoc.

Notes

  • .idea/dictionaries/project.xml is added; typically IDE files are excluded via .gitignore. If undesired in VCS, I can remove it from this PR and update .gitignore.

Checklist

  • Code compiles and tests pass locally
  • Package structure updated with package-info.java
  • New tests added for utilities and refactors
  • Build updated with publishing and verification
  • Javadoc builds cleanly
  • Confirm exclusion of IDE files (.idea) or remove from PR
  • Confirm no additional public API changes beyond package moves

Release Notes

  • Refactor: Move encoders to com.felipestanzani.jtoon.encoder.*, normalizer to com.felipestanzani.jtoon.normalizer.*, constants to com.felipestanzani.jtoon.util.Constants.
  • Feature: Add StringEscaper and StringValidator utilities.
  • Build: Add publishing and verification Gradle configs.
  • Tests: Add comprehensive unit tests for encoders, normalizer, and utilities.

- Removed unused constants from the Constants class, including PIPE, NEWLINE, CARRIAGE_RETURN, and TAB.
- Deleted redundant encode methods from the JToon class to streamline the encoding process.
- Introduced a comprehensive unit test suite for the JsonNormalizer utility, covering various input types and edge cases, ensuring robust functionality and correctness.
- Replaced traditional if-else statements with switch expressions for better clarity and conciseness in the normalize method and its helper functions.
- Updated the ProjectRootManager's language level in the IDE configuration from JDK_25 to JDK_21.
…n for normalization

- Introduced a list of normalization functions to streamline the normalization process for various data types.
- Replaced multiple conditional checks with a functional approach, enhancing readability and maintainability.
- Updated normalization methods for primitives, big numbers, and temporal types to improve clarity and efficiency.
- Simplified encoding methods by utilizing Java 21 switch expressions for primitive values.
- Delegated validation and escaping responsibilities to StringValidator and StringEscaper.
- Updated header formatting to use HeaderFormatter for improved modularity and readability.
- Removed unused regex patterns and redundant methods to streamline the class structure.
- Applied external Gradle scripts for publishing and verification to streamline build processes.
- Updated ProjectRootManager's language level to JDK_25 for improved compatibility.
- Introduced new encoding utilities, including ArrayEncoder, ObjectEncoder, and LineWriter, to enhance the encoding process for TOON format.
- Added JsonNormalizer for normalizing Java objects to Jackson JsonNode representation, supporting various data types.
- Implemented utility classes for string validation and escaping to ensure proper formatting in TOON output.
- Added comprehensive unit tests for encoding and normalization functionalities to ensure robustness and correctness.
@felipestanzani felipestanzani merged commit d58ddc9 into main Oct 30, 2025
1 check passed
@felipestanzani felipestanzani deleted the code_coverage 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