This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-4.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.18.x by this push:
     new 4f54047a582e CAMEL-23024: Fix yaml-io dumper for transacted
4f54047a582e is described below

commit 4f54047a582eeb436a26726777cbdd853293b210
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Feb 26 22:35:00 2026 +0100

    CAMEL-23024: Fix yaml-io dumper for transacted
---
 .../java/org/apache/camel/yaml/io/YamlWriter.java  | 15 ++++++++++++-
 .../org/apache/camel/yaml/out/ModelWriterTest.java | 20 +++++++++++++++++
 core/camel-yaml-io/src/test/resources/route16.yaml | 25 ++++++++++++++++++++++
 3 files changed, 59 insertions(+), 1 deletion(-)

diff --git 
a/core/camel-yaml-io/src/main/java/org/apache/camel/yaml/io/YamlWriter.java 
b/core/camel-yaml-io/src/main/java/org/apache/camel/yaml/io/YamlWriter.java
index 94a772d940c8..337f48a88c1f 100644
--- a/core/camel-yaml-io/src/main/java/org/apache/camel/yaml/io/YamlWriter.java
+++ b/core/camel-yaml-io/src/main/java/org/apache/camel/yaml/io/YamlWriter.java
@@ -195,6 +195,14 @@ public class YamlWriter extends ServiceSupport implements 
CamelContextAware {
             }
             // is this input/output on the parent
             EipModel parent = models.isEmpty() ? null : models.peek();
+            if (parent != null && parent.isAbstractModel()) {
+                // transacted/policy is special as they are abstract so we 
should go one level back
+                int pos = models.size() - 1;
+                var it = models.iterator();
+                for (int i = 0; i <= pos; i++) {
+                    parent = it.next();
+                }
+            }
             if (parent != null) {
                 if ("from".equals(name) && parent.isInput()) {
                     // only set input once
@@ -226,7 +234,12 @@ public class YamlWriter extends ServiceSupport implements 
CamelContextAware {
                         list = new ArrayList<>();
                         parent.getMetadata().put("_output", list);
                     }
-                    list.add(last);
+                    // abstracts are special and should be added in the top
+                    if (last.isAbstractModel()) {
+                        list.add(0, last);
+                    } else {
+                        list.add(last);
+                    }
                 } else if ("marshal".equals(parent.getName()) || 
"unmarshal".equals(parent.getName())) {
                     parent.getMetadata().put("_dataFormatType", last);
                 }
diff --git 
a/core/camel-yaml-io/src/test/java/org/apache/camel/yaml/out/ModelWriterTest.java
 
b/core/camel-yaml-io/src/test/java/org/apache/camel/yaml/out/ModelWriterTest.java
index b54d23e90710..c11ef22274bd 100644
--- 
a/core/camel-yaml-io/src/test/java/org/apache/camel/yaml/out/ModelWriterTest.java
+++ 
b/core/camel-yaml-io/src/test/java/org/apache/camel/yaml/out/ModelWriterTest.java
@@ -40,6 +40,7 @@ import org.apache.camel.model.SetVariableDefinition;
 import org.apache.camel.model.SetVariablesDefinition;
 import org.apache.camel.model.SplitDefinition;
 import org.apache.camel.model.ToDefinition;
+import org.apache.camel.model.TransactedDefinition;
 import org.apache.camel.model.dataformat.CsvDataFormat;
 import org.apache.camel.model.language.ConstantExpression;
 import org.apache.camel.model.language.HeaderExpression;
@@ -416,4 +417,23 @@ public class ModelWriterTest {
         Assertions.assertEquals(expected, out);
     }
 
+    @Test
+    public void testTransacted() throws Exception {
+        StringWriter sw = new StringWriter();
+        ModelWriter writer = new ModelWriter(sw);
+
+        RouteDefinition route = new RouteDefinition();
+        route.setId("myRout16");
+        route.setInput(new FromDefinition("jms:cheese"));
+        TransactedDefinition td = new TransactedDefinition();
+        route.addOutput(td);
+        td.addOutput(new ToDefinition("bean:foo"));
+
+        writer.writeRouteDefinition(route);
+
+        String out = sw.toString();
+        String expected = 
stripLineComments(Paths.get("src/test/resources/route16.yaml"), "#", true);
+        Assertions.assertEquals(expected, out);
+    }
+
 }
diff --git a/core/camel-yaml-io/src/test/resources/route16.yaml 
b/core/camel-yaml-io/src/test/resources/route16.yaml
new file mode 100644
index 000000000000..7685b45f3564
--- /dev/null
+++ b/core/camel-yaml-io/src/test/resources/route16.yaml
@@ -0,0 +1,25 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+- route:
+    id: myRout16
+    from:
+      uri: jms:cheese
+      steps:
+        - transacted: {}
+        - to:
+            uri: bean:foo

Reply via email to