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

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


The following commit(s) were added to refs/heads/main by this push:
     new eea446955b26 CAMEL-25636: camel-core - the label of marshal and 
unmarshal shows the name of the data format (#27809)
eea446955b26 is described below

commit eea446955b26ee2915e3dacf7ba6d104d7263486
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Oct 14 13:37:40 2026 +0200

    CAMEL-25636: camel-core - the label of marshal and unmarshal shows the name 
of the data format (#27809)
    
    Signed-off-by: Claus Ibsen <[email protected]>
    Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
---
 .../org/apache/camel/model/MarshalDefinition.java  | 14 +++-
 .../apache/camel/model/UnmarshalDefinition.java    | 14 +++-
 .../model/MarshalUnmarshalDefinitionLabelTest.java | 85 ++++++++++++++++++++++
 3 files changed, 109 insertions(+), 4 deletions(-)

diff --git 
a/core/camel-core-model/src/main/java/org/apache/camel/model/MarshalDefinition.java
 
b/core/camel-core-model/src/main/java/org/apache/camel/model/MarshalDefinition.java
index d48b784c760c..cc0e25e9cb7a 100644
--- 
a/core/camel-core-model/src/main/java/org/apache/camel/model/MarshalDefinition.java
+++ 
b/core/camel-core-model/src/main/java/org/apache/camel/model/MarshalDefinition.java
@@ -73,6 +73,7 @@ import 
org.apache.camel.model.dataformat.XMLSecurityDataFormat;
 import org.apache.camel.model.dataformat.YAMLDataFormat;
 import org.apache.camel.model.dataformat.ZipDeflaterDataFormat;
 import org.apache.camel.model.dataformat.ZipFileDataFormat;
+import org.apache.camel.spi.DataFormatName;
 import org.apache.camel.spi.Metadata;
 
 /**
@@ -178,7 +179,18 @@ public class MarshalDefinition extends 
NoOutputDefinition<MarshalDefinition> imp
     }
 
     protected String description() {
-        return dataFormatType != null ? dataFormatType.toString() : "";
+        if (dataFormatType == null) {
+            return "";
+        }
+        // the name of the data format (such as jackson or csv), as its 
toString is the object for most data formats
+        String name = dataFormatType.getDataFormatName();
+        if (name == null && dataFormatType.getDataFormat() instanceof 
DataFormatName dfn) {
+            name = dfn.getDataFormatName();
+        }
+        if (name == null && dataFormatType.getDataFormat() != null) {
+            name = dataFormatType.getDataFormat().getClass().getSimpleName();
+        }
+        return name != null ? name : dataFormatType.toString();
     }
 
     @Override
diff --git 
a/core/camel-core-model/src/main/java/org/apache/camel/model/UnmarshalDefinition.java
 
b/core/camel-core-model/src/main/java/org/apache/camel/model/UnmarshalDefinition.java
index 70818601e37a..0195fbaf2dfa 100644
--- 
a/core/camel-core-model/src/main/java/org/apache/camel/model/UnmarshalDefinition.java
+++ 
b/core/camel-core-model/src/main/java/org/apache/camel/model/UnmarshalDefinition.java
@@ -73,6 +73,7 @@ import 
org.apache.camel.model.dataformat.XMLSecurityDataFormat;
 import org.apache.camel.model.dataformat.YAMLDataFormat;
 import org.apache.camel.model.dataformat.ZipDeflaterDataFormat;
 import org.apache.camel.model.dataformat.ZipFileDataFormat;
+import org.apache.camel.spi.DataFormatName;
 import org.apache.camel.spi.Metadata;
 
 /**
@@ -176,11 +177,18 @@ public class UnmarshalDefinition extends 
NoOutputDefinition<UnmarshalDefinition>
     }
 
     protected String description() {
-        if (dataFormatType != null) {
-            return dataFormatType.toString();
-        } else {
+        if (dataFormatType == null) {
             return "";
         }
+        // the name of the data format (such as jackson or csv), as its 
toString is the object for most data formats
+        String name = dataFormatType.getDataFormatName();
+        if (name == null && dataFormatType.getDataFormat() instanceof 
DataFormatName dfn) {
+            name = dfn.getDataFormatName();
+        }
+        if (name == null && dataFormatType.getDataFormat() != null) {
+            name = dataFormatType.getDataFormat().getClass().getSimpleName();
+        }
+        return name != null ? name : dataFormatType.toString();
     }
 
     @Override
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/model/MarshalUnmarshalDefinitionLabelTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/model/MarshalUnmarshalDefinitionLabelTest.java
new file mode 100644
index 000000000000..be24a8a401b3
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/model/MarshalUnmarshalDefinitionLabelTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+package org.apache.camel.model;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.model.dataformat.CsvDataFormat;
+import org.apache.camel.model.dataformat.CustomDataFormat;
+import org.apache.camel.model.dataformat.DummyDataformat;
+import org.apache.camel.model.dataformat.JsonDataFormat;
+import org.apache.camel.model.dataformat.JsonLibrary;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.support.service.ServiceSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class MarshalUnmarshalDefinitionLabelTest {
+
+    @Test
+    public void testLabelShowsDataFormatName() {
+        assertEquals("unmarshal[jackson]", new UnmarshalDefinition(new 
JsonDataFormat()).getLabel());
+        assertEquals("Unmarshal[jackson]", new UnmarshalDefinition(new 
JsonDataFormat()).toString());
+        assertEquals("marshal[gson]", new MarshalDefinition(new 
JsonDataFormat(JsonLibrary.Gson)).getLabel());
+        assertEquals("Marshal[gson]", new MarshalDefinition(new 
JsonDataFormat(JsonLibrary.Gson)).toString());
+        assertEquals("marshal[csv]", new MarshalDefinition(new 
CsvDataFormat()).getLabel());
+        assertEquals("unmarshal[csv]", new UnmarshalDefinition(new 
CsvDataFormat()).getLabel());
+    }
+
+    @Test
+    public void testLabelOfDataFormatInstanceWithName() {
+        // DummyDataformat declares its name with DataFormatName
+        DataFormatDefinition instance = new DataFormatDefinition(new 
DummyDataformat());
+        assertEquals("marshal[dummy]", new 
MarshalDefinition(instance).getLabel());
+        assertEquals("unmarshal[dummy]", new 
UnmarshalDefinition(instance).getLabel());
+    }
+
+    @Test
+    public void testLabelOfDataFormatInstanceWithoutName() {
+        DataFormatDefinition instance = new DataFormatDefinition(new 
MyDataFormat());
+        assertEquals("marshal[MyDataFormat]", new 
MarshalDefinition(instance).getLabel());
+        assertEquals("unmarshal[MyDataFormat]", new 
UnmarshalDefinition(instance).getLabel());
+    }
+
+    @Test
+    public void testLabelOfCustomDataFormat() {
+        assertEquals("marshal[CustomDataFormat[myFormat]]", new 
MarshalDefinition(new CustomDataFormat("myFormat")).getLabel());
+        assertEquals("unmarshal[CustomDataFormat[myFormat]]",
+                new UnmarshalDefinition(new 
CustomDataFormat("myFormat")).getLabel());
+    }
+
+    @Test
+    public void testLabelWithoutDataFormat() {
+        assertEquals("marshal[]", new MarshalDefinition().getLabel());
+        assertEquals("unmarshal[]", new UnmarshalDefinition().getLabel());
+    }
+
+    private static class MyDataFormat extends ServiceSupport implements 
DataFormat {
+
+        @Override
+        public void marshal(Exchange exchange, Object graph, OutputStream 
stream) {
+        }
+
+        @Override
+        public Object unmarshal(Exchange exchange, InputStream stream) {
+            return null;
+        }
+    }
+}

Reply via email to