Skip to content

Conversation

@badpirogrammer2
Copy link

No description provided.

Core Implementation Complete: Full functionality for converting XML documents to TOON format is implemented.

New API Methods: Extended the main JToon.java class with new static methods for encoding:

encodeXml(String xml) (Basic conversion)

encodeXml(String xml, EncodeOptions options) (Conversion with custom options)

Dedicated Normalizer: Created XmlNormalizer.java to handle XML parsing using Jackson's XmlMapper and convert it to an intermediate JsonNode object.

Dependency Integration: Integrated the jackson-dataformat-xml dependency for robust XML parsing capabilities.

Comprehensive Structure Support: The conversion successfully handles:

Simple and nested XML elements (converted to TOON objects).

XML attributes (included as additional TOON fields).

XML arrays (converted to TOON arrays).

Preserves element hierarchy and ordering.

Full Options Support: The new methods support existing EncodeOptions for:

Custom indentation levels.

Different delimiters (comma, pipe, tab).

Length markers for arrays.

Robust Error Handling: Implemented checks to throw an IllegalArgumentException for:

Null or empty XML strings.

Malformed XML documents.

Invalid XML structure.

Extensive Testing:

449 total tests are passing (BUILD SUCCESSFUL).

Tests cover positive scenarios, negative/error handling, and complex edge cases (nested structures, attributes).

Documentation: Added comprehensive JavaDoc documentation with clear signatures and usage examples.
Copy link
Collaborator

@felipestanzani felipestanzani left a comment

Choose a reason for hiding this comment

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

Again, the tests are not complete.

Where are the conversion tests: given this I expect that?

Where are the tests for XmlNormalizer?

PRs won't be merged by insistence.

@felipestanzani felipestanzani marked this pull request as draft November 13, 2025 15:31
@felipestanzani felipestanzani marked this pull request as ready for review November 13, 2025 15:31
@felipestanzani felipestanzani marked this pull request as draft November 13, 2025 22:21
@felipestanzani
Copy link
Collaborator

Must resolve the conflicts.

 1. encodesXmlWithAttributes

Input XML:
<user id="123" active="true"><name>John</name><email>john@example.com</email></user>

Expected TOON Output:
id: "123"
active: "true"
name: John
email: john@example.com

 2. encodesDeeplyNestedXmlWithArrays

Input XML:
<company><name>TechCorp</name><departments><department><name>Engineering</name><employees><employee><name>Alice</name><role>Developer</role></employee><employee><name>Bob</name><role>Manager</role></employee></employees></department><department><name>Marketing</name><employees><employee><name>Carol</name><role>Director</role></employee></employees></department></departments></company>

Expected TOON Output:
name: TechCorp
departments:
  department[2]:
    - name: Engineering
      employees:
        employee[2]{name,role}:
          Alice,Developer
          Bob,Manager
    - name: Marketing
      employees:
        employee:
          name: Carol
          role: Director

 3. encodesXmlWithMixedContentAndAttributes

Input XML:
<book isbn="978-3-16-148410-0" category="fiction"><title>The Great Novel</title><author status="bestselling">Jane Doe</author><chapters><chapter number="1" title="Introduction">Welcome to the story</chapter><chapter number="2" title="Development">The plot thickens</chapter></chapters></book>

Expected TOON Output:
isbn: 978-3-16-148410-0
category: fiction
title: The Great Novel
author:
  status: bestselling
  "": Jane Doe
chapters:
  chapter[2]{number,title,""}:
    "1",Introduction,Welcome to the story
    "2",Development,The plot thickens

 Key Features Tested

- XML Attributes: Converted to regular object properties (no "@" prefix)
- Deep Nesting: Multi-level XML structures with arrays
- Mixed Content: Elements with both attributes and text content
- Array Detection: Similar child elements automatically become arrays
- Tabular Format: Arrays of similar objects use efficient tabular encoding

All tests now properly validate the expected TOON output strings, ensuring the XML to TOON conversion works correctly for complex XML structures.
@badpirogrammer2 badpirogrammer2 marked this pull request as ready for review November 14, 2025 15:28
@badpirogrammer2
Copy link
Author

XML Test Cases Added

  1. encodesXmlWithAttributes

Input XML:
Johnjohn@example.com

Expected TOON Output:
id: "123"
active: "true"
name: John
email: john@example.com

  1. encodesDeeplyNestedXmlWithArrays

Input XML:
TechCorpEngineeringAliceDeveloperBobManagerMarketingCarolDirector

Expected TOON Output:
name: TechCorp
departments:
department[2]:
- name: Engineering
employees:
employee[2]{name,role}:
Alice,Developer
Bob,Manager
- name: Marketing
employees:
employee:
name: Carol
role: Director

  1. encodesXmlWithMixedContentAndAttributes

Input XML:
<title>The Great Novel</title>Jane DoeWelcome to the storyThe plot thickens

Expected TOON Output:
isbn: 978-3-16-148410-0
category: fiction
title: The Great Novel
author:
status: bestselling
"": Jane Doe
chapters:
chapter[2]{number,title,""}:
"1",Introduction,Welcome to the story
"2",Development,The plot thickens

Key Features Tested

  • XML Attributes: Converted to regular object properties (no "@" prefix)
  • Deep Nesting: Multi-level XML structures with arrays
  • Mixed Content: Elements with both attributes and text content
  • Array Detection: Similar child elements automatically become arrays
  • Tabular Format: Arrays of similar objects use efficient tabular encoding

All tests now properly validate the expected TOON output strings, ensuring the XML to TOON conversion works correctly for complex XML structures.

@badpirogrammer2
Copy link
Author

@felipestanzani looks like there are many things in repo to add on top of this once you approve.

  • Input sanitization
  • resource Management

@felipestanzani
Copy link
Collaborator

We are currently focused on migrate the lib to the official toonformat property, so we are preparing this migration that require many steps.

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