davsclaus opened a new pull request, #30611: URL: https://github.com/apache/camel/pull/30611
Fixes CAMEL-27394. When `marshal` with `xsdJson` (JSON to XML) gets a JSON field that the schema does not declare, the error must be `IllegalArgumentException: The JSON field /getOrder/color is not declared ...`. In the `soap-action` Kamelet (camel-kamelets, `bodyFormat: json`), the exchange failed with `WstxOutputException: Trying to write END_DOCUMENT when document has no root` instead. ## Cause `XsdJsonDataFormat.marshal` closed the `XMLStreamWriter` in a `finally` block. When the mapping fails before the root element is written (an unknown field of the root), Woodstox fails to close the incomplete document, and an exception thrown from `finally` replaces the one in flight. The Kamelet has Woodstox on the classpath through CXF (`XMLOutputFactory.newFactory()` picks it). The StAX writer of the JDK does not fail on that close, so the module tests never showed it. ## Fix - The mapping error is thrown, and a failure to close the writer after it is added as suppressed. A complete document is closed as before. ## Tests - New `XsdJsonWoodstoxTest`, in its own surefire execution (`woodstox`) with `woodstox-core` on the classpath. It covers the Kamelet case (the WSDL as schema, the element from the `CamelXsdJsonElement` header, an unknown root field), an unknown nested field, and a complete document. Without the fix, the root case fails with the Woodstox error. - The other tests keep the StAX writer of the JDK: with Woodstox for all of them, three tests only differ in serialization style (`version='1.0'`, `<x/>`), which is equivalent XML. - All 42 tests of camel-xsd-json pass. _Claude Code on behalf of Claus Ibsen_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
