Skip to content

CAMEL-23596: Replace hand-written YamlWriter with generated direct YAML writer#23407

Merged
davsclaus merged 9 commits into
mainfrom
worktree-CAMEL-23593-normalize-rest-routeconfig
May 21, 2026
Merged

CAMEL-23596: Replace hand-written YamlWriter with generated direct YAML writer#23407
davsclaus merged 9 commits into
mainfrom
worktree-CAMEL-23593-normalize-rest-routeconfig

Conversation

@davsclaus
Copy link
Copy Markdown
Contributor

@davsclaus davsclaus commented May 21, 2026

Summary

Replace the old hand-written YAML writer stack with a new generated YamlModelWriter that builds JsonObject/JsonArray structures and serializes via YamlPrinter.

  • New code generation: model-yaml-writer.vm Velocity template generates YamlModelWriter with doWrite* methods returning JsonObject
  • New serializer: YamlPrinter converts JsonObject/JsonArray to YAML strings without Jackson
  • Structural fixes: Steps placed under from (not route level), expression: wrapper for expression nodes, ${...} string quoting
  • Old code removed: ModelWriter.java (generated), BaseWriter.java, YamlWriter.java (600 lines hand-written), old generator mojo, old tests
  • Mojo renamed: YamlDirectModelWriterGeneratorMojoYamlModelWriterGeneratorMojo (goal: generate-yaml-writer)
  • 48 new tests in YamlModelWriterTest covering all major EIP patterns
  • Migrated consumers: TransformTools, XmlToYamlTest, XPathNamespacesTest updated to use new writer

Test plan

  • All 113 tests pass in camel-yaml-io (48 YamlModelWriter + 53 XmlToYaml + 1 XPathNamespaces + 11 others)
  • All 10 DumpModelAsYaml* tests pass in camel-core
  • All 3 ManagedCamelContextDumpRoutesAsYamlTest tests pass in camel-management

Claude Code on behalf of Claus Ibsen

🤖 Generated with Claude Code

@github-actions github-actions Bot added the core label May 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

🧪 CI tested the following changed modules:

  • core/camel-yaml-io
  • dsl/camel-jbang/camel-jbang-mcp
  • tooling/maven/camel-package-maven-plugin

ℹ️ Dependent modules were not tested because the total number of affected modules exceeded the threshold (50). Use the test-dependents label to force testing all dependents.

⚠️ Some tests are disabled on GitHub Actions (@DisabledIfSystemProperty(named = "ci.env.name")) and require manual verification:

  • dsl/camel-jbang/camel-jbang-mcp: 1 test(s) disabled on GitHub Actions
Build reactor — dependencies compiled but only changed modules were tested (3 modules)
  • Camel :: JBang :: MCP
  • Camel :: Maven Plugins :: Camel Maven Package
  • Camel :: YAML IO

⚙️ View full build and test results

davsclaus and others added 8 commits May 21, 2026 12:25
…ation

Add a lightweight YamlPrinter that serializes Map/Collection structures
to block-style YAML text without any Jackson dependency. This is the
foundation for replacing the hand-written YamlWriter with a generated
direct YAML writer.

Co-Authored-By: Claude <noreply@anthropic.com>
…erated direct YAML writer

Replace the 600-line hand-written YamlWriter (with 43+ hardcoded special cases)
with a generated YamlModelWriter that builds JsonObject/JsonArray structures
directly from model classes and serializes them via YamlPrinter.

New pipeline (2 conversions):
  Model -> Generated YamlModelWriter -> JsonObject -> YamlPrinter -> YAML String

Old pipeline (6 conversions):
  Model -> ModelWriter -> YamlWriter -> EipNode -> JsonObject -> Jackson -> YAML

Key changes:
- New Velocity template model-yaml-writer.vm that generates doWrite* methods
  returning JsonObject instead of emitting XML-style startElement/endElement
- New YamlDirectModelWriterGeneratorMojo that generates YamlModelWriter.java
- New YamlModelWriterSupport base class with helper methods for building
  JsonObject structures (doWriteAttribute, doWriteChildElement, expandUri, etc.)
- LwModelToYAMLDumper now uses YamlModelWriter instead of old ModelWriter
- Property classification happens at code-generation time, not runtime,
  eliminating the root cause of CAMEL-23593 bugs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…riter tests

Fix three structural issues in generated YamlModelWriter:
- Move steps from route level into from child (doMoveStepsUnderFrom)
- Add expression wrapper key for ExpressionNode refs (doWriteExpressionRef)
- Quote YAML strings containing ${ and {{ sequences
- Preserve empty child elements like csv: {} for data format type info
- Use doWriteChildList for non-outputs @XmlElementRef lists (choice when)
- Remove alphabetical sorting in expandUri to match catalog parameter order

Add 24 YamlModelWriter tests covering: simple route, two routes, choice,
transform, marshal/unmarshal, multicast, wireTap, split, circuitBreaker,
routeConfiguration, routeTemplate, REST DSL, filter, loadBalance (round-robin
and failover), dynamicRouter, routingSlip, recipientList, enrich/pollEnrich,
delay, throttle, validate, idempotentConsumer, and onCompletion.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…m-priority EIPs

Add 15 additional tests covering: try/catch/finally, saga, setVariable,
setProperty, removeHeader/Property/Variable, convertBody/Header, loop,
step, pipeline, toDynamic, process, bean, resequence, claimCheck,
sampling, threads, sort, script, rollback, stop, throwException,
onException (standalone with redeliveryPolicy), and poll.

Total YamlModelWriter tests: 39, exercising 73 model types.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…transformers, validators, kamelet, transacted

Add 7 additional YamlModelWriter tests covering:
- ErrorHandler: DeadLetterChannel with redeliveryPolicy, DefaultErrorHandler
- RestConfiguration: component, host, port, bindingMode, contextPath
- Transformers: EndpointTransformerDefinition with fromType/toType
- Validators: EndpointValidatorDefinition with type
- Kamelet: kamelet EIP with name and nested steps
- Transacted: transacted EIP with ref and nested steps

Total YamlModelWriter tests: 46.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…on and BeansDefinition)

Add 2 tests for bean definitions:
- testBeans: BeanFactoryDefinition with properties, factoryMethod, init/destroy
- testBeansWithRoute: BeansDefinition container with bean + route

Total YamlModelWriter tests: 48.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…Writer and generator

The old YAML writer stack (ModelWriter extending BaseWriter using YamlWriter)
is fully replaced by the new generated YamlModelWriter. Remove the old code
and migrate remaining consumers (TransformTools, XmlToYamlTest, XPathNamespacesTest).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…o to YamlModelWriterGeneratorMojo

The "Direct" qualifier was only needed to distinguish from the old mojo
that has been removed. Rename the mojo, goal, and property to the simpler
names: generate-yaml-writer and camel-generate-yaml-writer.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@davsclaus davsclaus force-pushed the worktree-CAMEL-23593-normalize-rest-routeconfig branch from 6e11b1a to 89f41f3 Compare May 21, 2026 10:25
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@davsclaus davsclaus merged commit af41850 into main May 21, 2026
6 checks passed
@davsclaus davsclaus deleted the worktree-CAMEL-23593-normalize-rest-routeconfig branch May 21, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant