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

davsclaus pushed a commit to branch CAMEL-27302-isPojo-file
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 30fe4e698a60c99b3a4748bec1ba8dc03446e7ab
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Nov 20 14:06:08 2026 +0100

    CAMEL-27302: camel-jackson - a file body is no POJO for the content class 
of a schema
    
    Since CAMEL-27267 the binary (application-octet-stream) data type keeps a
    File, Path or WrappedFile body, so a file from a file, FTP or Azure Files
    consumer can reach SchemaHelper.resolveContentClass, used by the schema
    resolvers (resolve-pojo-schema-action). isPojo took GenericFile and the 
other
    WrappedFile classes for a POJO and set their class as the content class, so 
the
    Avro and Protobuf data types serialized the file object instead of its 
content.
    
    A WrappedFile is a handle to raw content and is no POJO, as for StreamCache 
in
    apache/camel#30458, in camel-jackson and camel-jackson3. java.io.File and
    java.nio.file.Path were already no POJO (java package).
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../camel/component/jackson/SchemaHelper.java      |  5 +++
 .../camel/component/jackson/SchemaHelperTest.java  | 44 ++++++++++++++++++++++
 .../camel/component/jackson3/SchemaHelper.java     |  5 +++
 .../camel/component/jackson3/SchemaHelperTest.java | 44 ++++++++++++++++++++++
 4 files changed, 98 insertions(+)

diff --git 
a/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/SchemaHelper.java
 
b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/SchemaHelper.java
index fa632935ffdc..0aa2dc55dc01 100644
--- 
a/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/SchemaHelper.java
+++ 
b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/SchemaHelper.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.jackson;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.StreamCache;
+import org.apache.camel.WrappedFile;
 
 public class SchemaHelper {
 
@@ -79,6 +80,10 @@ public class SchemaHelper {
             // a stream cache holds the raw content, such as the body of an 
HTTP request, and is no POJO
             return false;
         }
+        if (WrappedFile.class.isAssignableFrom(type)) {
+            // a file from a file, FTP or similar consumer (such as 
GenericFile) is a handle to raw content, and is no POJO
+            return false;
+        }
 
         Package pkg = type.getPackage();
         if (pkg != null) {
diff --git 
a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SchemaHelperTest.java
 
b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SchemaHelperTest.java
index 31b8ead6ad2c..fad28145c554 100644
--- 
a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SchemaHelperTest.java
+++ 
b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SchemaHelperTest.java
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.component.jackson;
 
+import java.io.File;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.WrappedFile;
 import org.apache.camel.converter.stream.InputStreamCache;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.support.DefaultExchange;
@@ -51,4 +54,45 @@ class SchemaHelperTest {
         exchange.getMessage().setBody(new TestPojo());
         assertEquals(TestPojo.class.getName(), 
SchemaHelper.resolveContentClass(exchange, null));
     }
+
+    @Test
+    void fileIsNoPojo() {
+        // CAMEL-27302: the binary data type keeps a file body (CAMEL-27267), 
which is a handle to raw content and is no POJO
+        assertFalse(SchemaHelper.isPojo(TestWrappedFile.class));
+        assertFalse(SchemaHelper.isPojo(File.class));
+        assertFalse(SchemaHelper.isPojo(Path.class));
+    }
+
+    @Test
+    void fileBodyHasNoContentClass() {
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
+        exchange.getMessage().setBody(new TestWrappedFile(new 
File("target/person.json")));
+
+        assertNull(SchemaHelper.resolveContentClass(exchange, null));
+        assertEquals("fallback", SchemaHelper.resolveContentClass(exchange, 
"fallback"));
+    }
+
+    private static final class TestWrappedFile implements WrappedFile<File> {
+
+        private final File file;
+
+        TestWrappedFile(File file) {
+            this.file = file;
+        }
+
+        @Override
+        public File getFile() {
+            return file;
+        }
+
+        @Override
+        public Object getBody() {
+            return file;
+        }
+
+        @Override
+        public long getFileLength() {
+            return file.length();
+        }
+    }
 }
diff --git 
a/components/camel-jackson3/src/main/java/org/apache/camel/component/jackson3/SchemaHelper.java
 
b/components/camel-jackson3/src/main/java/org/apache/camel/component/jackson3/SchemaHelper.java
index abd5b0faf290..ce2cc3c8e47b 100644
--- 
a/components/camel-jackson3/src/main/java/org/apache/camel/component/jackson3/SchemaHelper.java
+++ 
b/components/camel-jackson3/src/main/java/org/apache/camel/component/jackson3/SchemaHelper.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.jackson3;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.StreamCache;
+import org.apache.camel.WrappedFile;
 
 public class SchemaHelper {
 
@@ -79,6 +80,10 @@ public class SchemaHelper {
             // a stream cache holds the raw content, such as the body of an 
HTTP request, and is no POJO
             return false;
         }
+        if (WrappedFile.class.isAssignableFrom(type)) {
+            // a file from a file, FTP or similar consumer (such as 
GenericFile) is a handle to raw content, and is no POJO
+            return false;
+        }
 
         Package pkg = type.getPackage();
         if (pkg != null) {
diff --git 
a/components/camel-jackson3/src/test/java/org/apache/camel/component/jackson3/SchemaHelperTest.java
 
b/components/camel-jackson3/src/test/java/org/apache/camel/component/jackson3/SchemaHelperTest.java
index 75b2dec8095f..97f15d118772 100644
--- 
a/components/camel-jackson3/src/test/java/org/apache/camel/component/jackson3/SchemaHelperTest.java
+++ 
b/components/camel-jackson3/src/test/java/org/apache/camel/component/jackson3/SchemaHelperTest.java
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.component.jackson3;
 
+import java.io.File;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.WrappedFile;
 import org.apache.camel.converter.stream.InputStreamCache;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.support.DefaultExchange;
@@ -51,4 +54,45 @@ class SchemaHelperTest {
         exchange.getMessage().setBody(new TestPojo());
         assertEquals(TestPojo.class.getName(), 
SchemaHelper.resolveContentClass(exchange, null));
     }
+
+    @Test
+    void fileIsNoPojo() {
+        // CAMEL-27302: the binary data type keeps a file body (CAMEL-27267), 
which is a handle to raw content and is no POJO
+        assertFalse(SchemaHelper.isPojo(TestWrappedFile.class));
+        assertFalse(SchemaHelper.isPojo(File.class));
+        assertFalse(SchemaHelper.isPojo(Path.class));
+    }
+
+    @Test
+    void fileBodyHasNoContentClass() {
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
+        exchange.getMessage().setBody(new TestWrappedFile(new 
File("target/person.json")));
+
+        assertNull(SchemaHelper.resolveContentClass(exchange, null));
+        assertEquals("fallback", SchemaHelper.resolveContentClass(exchange, 
"fallback"));
+    }
+
+    private static final class TestWrappedFile implements WrappedFile<File> {
+
+        private final File file;
+
+        TestWrappedFile(File file) {
+            this.file = file;
+        }
+
+        @Override
+        public File getFile() {
+            return file;
+        }
+
+        @Override
+        public Object getBody() {
+            return file;
+        }
+
+        @Override
+        public long getFileLength() {
+            return file.length();
+        }
+    }
 }

Reply via email to