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 8f2a6ae72182 [backport camel-4.18.x] CAMEL-27052: camel-jaxb - the 
part class and namespace headers are used only when allowPartClassFromHeader is 
enabled (#30347)
8f2a6ae72182 is described below

commit 8f2a6ae721821e4cf5d005bd4e7d490feeb8abf3
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Nov 18 21:56:07 2026 +0100

    [backport camel-4.18.x] CAMEL-27052: camel-jaxb - the part class and 
namespace headers are used only when allowPartClassFromHeader is enabled 
(#30347)
    
    Backport of #30212 (f8036a4c9354), on top of CAMEL-24164 (#24813, 
17c24197597b), which it needs.
    
    CAMEL-24164: a CamelJaxbPartClass or CamelJaxbPartNamespace header no 
longer changes the partClass and partNamespace of
    the data format; it applies to its own message only, so later messages 
without the header use the configured values.
    
    CAMEL-27052: the JAXB data format always read the CamelJaxbPartClass and 
CamelJaxbPartNamespace headers, on unmarshal
    and marshal, and when set they took precedence over the partClass and 
partNamespace options. A new option
    allowPartClassFromHeader (default false) makes them opt-in, in line with 
allowUnmarshallType of the Jackson, Gson and
    JSON-B data formats. When disabled, the headers are ignored and the 
configured partClass and partNamespace apply.
    
    The SOAP data format extends the JAXB data format and always ignores these 
headers. The Rest DSL binding on this branch
    does not take options from the JAXB data format on the CamelContext, so the 
RestBindingAdviceFactory change of #30212 is
    not needed here. The upgrade note is in the 4.18 upgrade guide on main 
(#30348).
    
    Co-authored-by: Federico Mariani <[email protected]>
    Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../org/apache/camel/catalog/dataformats/jaxb.json |  15 ++-
 .../org/apache/camel/catalog/models/jaxb.json      |  15 ++-
 .../apache/camel/catalog/schemas/camel-spring.xsd  |  11 ++
 .../apache/camel/catalog/schemas/camel-xml-io.xsd  |  11 ++
 .../converter/jaxb/JaxbDataFormatConfigurer.java   |   7 +
 .../org/apache/camel/converter/jaxb/jaxb.json      |  15 ++-
 .../camel-jaxb/src/main/docs/jaxb-dataformat.adoc  |  32 +++--
 .../camel/converter/jaxb/JaxbDataFormat.java       |  49 +++++--
 .../jaxb/JaxbDataFormatPartClassHeaderTest.java    |   1 +
 .../jaxb/JaxbPartClassHeaderOptionTest.java        | 124 ++++++++++++++++++
 .../JaxbPartClassHeaderStatePollutionTest.java     | 142 +++++++++++++++++++++
 .../rest/RestJettyNoContentRestConfigTest.java     |   3 +-
 .../jetty/rest/RestJettyNoContentTest.java         |   3 +-
 .../rest/RestServletNoContentRestConfigTest.java   |   3 +-
 .../servlet/rest/RestServletNoContentTest.java     |   3 +-
 .../camel/dataformat/soap/SoapUnMarshalTest.java   |  15 +++
 .../org/apache/camel/model/dataformat/jaxb.json    |  15 ++-
 .../camel/model/dataformat/JaxbDataFormat.java     |  39 ++++++
 .../reifier/dataformat/JaxbDataFormatReifier.java  |   1 +
 .../java/org/apache/camel/xml/in/ModelParser.java  |   1 +
 .../java/org/apache/camel/xml/out/ModelWriter.java |   1 +
 .../org/apache/camel/yaml/out/ModelWriter.java     |   1 +
 .../dsl/yaml/deserializers/ModelDeserializers.java |   6 +
 .../generated/resources/schema/camelYamlDsl.json   |   6 +
 24 files changed, 463 insertions(+), 56 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/jaxb.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/jaxb.json
index ba39d5a62b9b..7d0d1464c978 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/jaxb.json
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/jaxb.json
@@ -30,12 +30,13 @@
     "fragment": { "index": 11, "kind": "attribute", "displayName": "Fragment", 
"group": "advanced", "label": "advanced", "required": false, "type": "boolean", 
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": false, "description": "To turn on marshalling 
XML fragment trees. By default JAXB looks for XmlRootElement annotation on 
given class to operate on whole XML tree. This is useful but not always - 
sometimes generated code does n [...]
     "partClass": { "index": 12, "kind": "attribute", "displayName": "Part 
Class", "group": "advanced", "label": "advanced", "required": false, "type": 
"string", "javaType": "java.lang.String", "deprecated": false, "autowired": 
false, "secret": false, "description": "Name of class used for fragment 
parsing. See more details at the fragment option." },
     "partNamespace": { "index": 13, "kind": "attribute", "displayName": "Part 
Namespace", "group": "advanced", "label": "advanced", "required": false, 
"type": "string", "javaType": "java.lang.String", "deprecated": false, 
"autowired": false, "secret": false, "description": "XML namespace to use for 
fragment parsing. See more details at the fragment option." },
-    "namespacePrefix": { "index": 14, "kind": "attribute", "displayName": 
"Namespace Prefix", "group": "advanced", "label": "advanced", "required": 
false, "type": "object", "javaType": "java.util.Map", "deprecated": false, 
"autowired": false, "secret": false, "description": "When marshalling using 
JAXB or SOAP then the JAXB implementation will automatically assign namespace 
prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you 
to refer to a map which contains the [...]
-    "xmlStreamWriterWrapper": { "index": 15, "kind": "attribute", 
"displayName": "Xml Stream Writer Wrapper", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "To use a custom xml stream writer." },
-    "schemaLocation": { "index": 16, "kind": "attribute", "displayName": 
"Schema Location", "group": "common", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "To define the location of the schema" },
-    "noNamespaceSchemaLocation": { "index": 17, "kind": "attribute", 
"displayName": "No Namespace Schema Location", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "To define the location of the namespaceless schema" },
-    "jaxbProviderProperties": { "index": 18, "kind": "attribute", 
"displayName": "Jaxb Provider Properties", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Refers to a custom java.util.Map to lookup in the registry 
containing custom JAXB provider properties to be used with the JAXB 
marshaller." },
-    "contentTypeHeader": { "index": 19, "kind": "attribute", "displayName": 
"Content Type Header", "group": "common", "required": false, "type": "boolean", 
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": true, "description": "Whether the data format 
should set the Content-Type header with the type from the data format. For 
example application\/xml for data formats marshalling to XML, or 
application\/json for data formats marshall [...]
-    "accessExternalSchemaProtocols": { "index": 20, "kind": "attribute", 
"displayName": "Access External Schema Protocols", "group": "security", 
"label": "security", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Only in use if schema validation has been enabled. Restrict 
access to the protocols specified for external reference set by the 
schemaLocation attribute, Import and Include element. E [...]
+    "allowPartClassFromHeader": { "index": 14, "kind": "attribute", 
"displayName": "Allow Part Class From Header", "group": "advanced", "label": 
"advanced", "required": false, "type": "boolean", "javaType": 
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": false, "description": "Whether the CamelJaxbPartClass and 
CamelJaxbPartNamespace headers are used, when set, instead of the partClass and 
partNamespace options when marshalling and unmarshal [...]
+    "namespacePrefix": { "index": 15, "kind": "attribute", "displayName": 
"Namespace Prefix", "group": "advanced", "label": "advanced", "required": 
false, "type": "object", "javaType": "java.util.Map", "deprecated": false, 
"autowired": false, "secret": false, "description": "When marshalling using 
JAXB or SOAP then the JAXB implementation will automatically assign namespace 
prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you 
to refer to a map which contains the [...]
+    "xmlStreamWriterWrapper": { "index": 16, "kind": "attribute", 
"displayName": "Xml Stream Writer Wrapper", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "To use a custom xml stream writer." },
+    "schemaLocation": { "index": 17, "kind": "attribute", "displayName": 
"Schema Location", "group": "common", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "To define the location of the schema" },
+    "noNamespaceSchemaLocation": { "index": 18, "kind": "attribute", 
"displayName": "No Namespace Schema Location", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "To define the location of the namespaceless schema" },
+    "jaxbProviderProperties": { "index": 19, "kind": "attribute", 
"displayName": "Jaxb Provider Properties", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Refers to a custom java.util.Map to lookup in the registry 
containing custom JAXB provider properties to be used with the JAXB 
marshaller." },
+    "contentTypeHeader": { "index": 20, "kind": "attribute", "displayName": 
"Content Type Header", "group": "common", "required": false, "type": "boolean", 
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": true, "description": "Whether the data format 
should set the Content-Type header with the type from the data format. For 
example application\/xml for data formats marshalling to XML, or 
application\/json for data formats marshall [...]
+    "accessExternalSchemaProtocols": { "index": 21, "kind": "attribute", 
"displayName": "Access External Schema Protocols", "group": "security", 
"label": "security", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Only in use if schema validation has been enabled. Restrict 
access to the protocols specified for external reference set by the 
schemaLocation attribute, Import and Include element. E [...]
   }
 }
diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/jaxb.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/jaxb.json
index e59e07fc6fc6..4f7f4aa67263 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/jaxb.json
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/jaxb.json
@@ -27,12 +27,13 @@
     "fragment": { "index": 11, "kind": "attribute", "displayName": "Fragment", 
"group": "advanced", "label": "advanced", "required": false, "type": "boolean", 
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": false, "description": "To turn on marshalling 
XML fragment trees. By default JAXB looks for XmlRootElement annotation on 
given class to operate on whole XML tree. This is useful but not always - 
sometimes generated code does n [...]
     "partClass": { "index": 12, "kind": "attribute", "displayName": "Part 
Class", "group": "advanced", "label": "advanced", "required": false, "type": 
"string", "javaType": "java.lang.String", "deprecated": false, "autowired": 
false, "secret": false, "description": "Name of class used for fragment 
parsing. See more details at the fragment option." },
     "partNamespace": { "index": 13, "kind": "attribute", "displayName": "Part 
Namespace", "group": "advanced", "label": "advanced", "required": false, 
"type": "string", "javaType": "java.lang.String", "deprecated": false, 
"autowired": false, "secret": false, "description": "XML namespace to use for 
fragment parsing. See more details at the fragment option." },
-    "namespacePrefix": { "index": 14, "kind": "attribute", "displayName": 
"Namespace Prefix", "group": "advanced", "label": "advanced", "required": 
false, "type": "object", "javaType": "java.util.Map", "deprecated": false, 
"autowired": false, "secret": false, "description": "When marshalling using 
JAXB or SOAP then the JAXB implementation will automatically assign namespace 
prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you 
to refer to a map which contains the [...]
-    "xmlStreamWriterWrapper": { "index": 15, "kind": "attribute", 
"displayName": "Xml Stream Writer Wrapper", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "To use a custom xml stream writer." },
-    "schemaLocation": { "index": 16, "kind": "attribute", "displayName": 
"Schema Location", "group": "common", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "To define the location of the schema" },
-    "noNamespaceSchemaLocation": { "index": 17, "kind": "attribute", 
"displayName": "No Namespace Schema Location", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "To define the location of the namespaceless schema" },
-    "jaxbProviderProperties": { "index": 18, "kind": "attribute", 
"displayName": "Jaxb Provider Properties", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Refers to a custom java.util.Map to lookup in the registry 
containing custom JAXB provider properties to be used with the JAXB 
marshaller." },
-    "contentTypeHeader": { "index": 19, "kind": "attribute", "displayName": 
"Content Type Header", "group": "common", "required": false, "type": "boolean", 
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": true, "description": "Whether the data format 
should set the Content-Type header with the type from the data format. For 
example application\/xml for data formats marshalling to XML, or 
application\/json for data formats marshall [...]
-    "accessExternalSchemaProtocols": { "index": 20, "kind": "attribute", 
"displayName": "Access External Schema Protocols", "group": "security", 
"label": "security", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Only in use if schema validation has been enabled. Restrict 
access to the protocols specified for external reference set by the 
schemaLocation attribute, Import and Include element. E [...]
+    "allowPartClassFromHeader": { "index": 14, "kind": "attribute", 
"displayName": "Allow Part Class From Header", "group": "advanced", "label": 
"advanced", "required": false, "type": "boolean", "javaType": 
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": false, "description": "Whether the CamelJaxbPartClass and 
CamelJaxbPartNamespace headers are used, when set, instead of the partClass and 
partNamespace options when marshalling and unmarshal [...]
+    "namespacePrefix": { "index": 15, "kind": "attribute", "displayName": 
"Namespace Prefix", "group": "advanced", "label": "advanced", "required": 
false, "type": "object", "javaType": "java.util.Map", "deprecated": false, 
"autowired": false, "secret": false, "description": "When marshalling using 
JAXB or SOAP then the JAXB implementation will automatically assign namespace 
prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you 
to refer to a map which contains the [...]
+    "xmlStreamWriterWrapper": { "index": 16, "kind": "attribute", 
"displayName": "Xml Stream Writer Wrapper", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "To use a custom xml stream writer." },
+    "schemaLocation": { "index": 17, "kind": "attribute", "displayName": 
"Schema Location", "group": "common", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "To define the location of the schema" },
+    "noNamespaceSchemaLocation": { "index": 18, "kind": "attribute", 
"displayName": "No Namespace Schema Location", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "To define the location of the namespaceless schema" },
+    "jaxbProviderProperties": { "index": 19, "kind": "attribute", 
"displayName": "Jaxb Provider Properties", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Refers to a custom java.util.Map to lookup in the registry 
containing custom JAXB provider properties to be used with the JAXB 
marshaller." },
+    "contentTypeHeader": { "index": 20, "kind": "attribute", "displayName": 
"Content Type Header", "group": "common", "required": false, "type": "boolean", 
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": true, "description": "Whether the data format 
should set the Content-Type header with the type from the data format. For 
example application\/xml for data formats marshalling to XML, or 
application\/json for data formats marshall [...]
+    "accessExternalSchemaProtocols": { "index": 21, "kind": "attribute", 
"displayName": "Access External Schema Protocols", "group": "security", 
"label": "security", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Only in use if schema validation has been enabled. Restrict 
access to the protocols specified for external reference set by the 
schemaLocation attribute, Import and Include element. E [...]
   }
 }
diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
index 369cbaf34618..61c75accacac 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
@@ -9429,6 +9429,17 @@ Name of class used for fragment parsing. See more 
details at the fragment option
             <xs:documentation xml:lang="en">
 <![CDATA[
 XML namespace to use for fragment parsing. See more details at the fragment 
option.
+]]>
+            </xs:documentation>
+          </xs:annotation>
+        </xs:attribute>
+        <xs:attribute name="allowPartClassFromHeader" type="xs:string">
+          <xs:annotation>
+            <xs:documentation xml:lang="en">
+<![CDATA[
+Whether the CamelJaxbPartClass and CamelJaxbPartNamespace headers are used, 
when set, instead of the partClass and
+partNamespace options when marshalling and unmarshalling. Enable it only when 
the route sets these headers itself, not
+on routes that receive them from external systems. Default value: false
 ]]>
             </xs:documentation>
           </xs:annotation>
diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd
index 2320af84ae96..978f4e954553 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd
@@ -8102,6 +8102,17 @@ Name of class used for fragment parsing. See more 
details at the fragment option
             <xs:documentation xml:lang="en">
 <![CDATA[
 XML namespace to use for fragment parsing. See more details at the fragment 
option.
+]]>
+            </xs:documentation>
+          </xs:annotation>
+        </xs:attribute>
+        <xs:attribute name="allowPartClassFromHeader" type="xs:string">
+          <xs:annotation>
+            <xs:documentation xml:lang="en">
+<![CDATA[
+Whether the CamelJaxbPartClass and CamelJaxbPartNamespace headers are used, 
when set, instead of the partClass and
+partNamespace options when marshalling and unmarshalling. Enable it only when 
the route sets these headers itself, not
+on routes that receive them from external systems. Default value: false
 ]]>
             </xs:documentation>
           </xs:annotation>
diff --git 
a/components/camel-jaxb/src/generated/java/org/apache/camel/converter/jaxb/JaxbDataFormatConfigurer.java
 
b/components/camel-jaxb/src/generated/java/org/apache/camel/converter/jaxb/JaxbDataFormatConfigurer.java
index 82d228749d68..92829bdc5b76 100644
--- 
a/components/camel-jaxb/src/generated/java/org/apache/camel/converter/jaxb/JaxbDataFormatConfigurer.java
+++ 
b/components/camel-jaxb/src/generated/java/org/apache/camel/converter/jaxb/JaxbDataFormatConfigurer.java
@@ -23,6 +23,7 @@ public class JaxbDataFormatConfigurer extends 
org.apache.camel.support.component
     static {
         Map<String, Object> map = new CaseInsensitiveMap();
         map.put("AccessExternalSchemaProtocols", java.lang.String.class);
+        map.put("AllowPartClassFromHeader", boolean.class);
         map.put("ContentTypeHeader", boolean.class);
         map.put("ContextPath", java.lang.String.class);
         map.put("ContextPathIsClassName", boolean.class);
@@ -51,6 +52,8 @@ public class JaxbDataFormatConfigurer extends 
org.apache.camel.support.component
         switch (ignoreCase ? name.toLowerCase() : name) {
         case "accessexternalschemaprotocols":
         case "accessExternalSchemaProtocols": 
target.setAccessExternalSchemaProtocols(property(camelContext, 
java.lang.String.class, value)); return true;
+        case "allowpartclassfromheader":
+        case "allowPartClassFromHeader": 
target.setAllowPartClassFromHeader(property(camelContext, boolean.class, 
value)); return true;
         case "contenttypeheader":
         case "contentTypeHeader": 
target.setContentTypeHeader(property(camelContext, boolean.class, value)); 
return true;
         case "contextpath":
@@ -100,6 +103,8 @@ public class JaxbDataFormatConfigurer extends 
org.apache.camel.support.component
         switch (ignoreCase ? name.toLowerCase() : name) {
         case "accessexternalschemaprotocols":
         case "accessExternalSchemaProtocols": return java.lang.String.class;
+        case "allowpartclassfromheader":
+        case "allowPartClassFromHeader": return boolean.class;
         case "contenttypeheader":
         case "contentTypeHeader": return boolean.class;
         case "contextpath":
@@ -145,6 +150,8 @@ public class JaxbDataFormatConfigurer extends 
org.apache.camel.support.component
         switch (ignoreCase ? name.toLowerCase() : name) {
         case "accessexternalschemaprotocols":
         case "accessExternalSchemaProtocols": return 
target.getAccessExternalSchemaProtocols();
+        case "allowpartclassfromheader":
+        case "allowPartClassFromHeader": return 
target.isAllowPartClassFromHeader();
         case "contenttypeheader":
         case "contentTypeHeader": return target.isContentTypeHeader();
         case "contextpath":
diff --git 
a/components/camel-jaxb/src/generated/resources/META-INF/org/apache/camel/converter/jaxb/jaxb.json
 
b/components/camel-jaxb/src/generated/resources/META-INF/org/apache/camel/converter/jaxb/jaxb.json
index ba39d5a62b9b..7d0d1464c978 100644
--- 
a/components/camel-jaxb/src/generated/resources/META-INF/org/apache/camel/converter/jaxb/jaxb.json
+++ 
b/components/camel-jaxb/src/generated/resources/META-INF/org/apache/camel/converter/jaxb/jaxb.json
@@ -30,12 +30,13 @@
     "fragment": { "index": 11, "kind": "attribute", "displayName": "Fragment", 
"group": "advanced", "label": "advanced", "required": false, "type": "boolean", 
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": false, "description": "To turn on marshalling 
XML fragment trees. By default JAXB looks for XmlRootElement annotation on 
given class to operate on whole XML tree. This is useful but not always - 
sometimes generated code does n [...]
     "partClass": { "index": 12, "kind": "attribute", "displayName": "Part 
Class", "group": "advanced", "label": "advanced", "required": false, "type": 
"string", "javaType": "java.lang.String", "deprecated": false, "autowired": 
false, "secret": false, "description": "Name of class used for fragment 
parsing. See more details at the fragment option." },
     "partNamespace": { "index": 13, "kind": "attribute", "displayName": "Part 
Namespace", "group": "advanced", "label": "advanced", "required": false, 
"type": "string", "javaType": "java.lang.String", "deprecated": false, 
"autowired": false, "secret": false, "description": "XML namespace to use for 
fragment parsing. See more details at the fragment option." },
-    "namespacePrefix": { "index": 14, "kind": "attribute", "displayName": 
"Namespace Prefix", "group": "advanced", "label": "advanced", "required": 
false, "type": "object", "javaType": "java.util.Map", "deprecated": false, 
"autowired": false, "secret": false, "description": "When marshalling using 
JAXB or SOAP then the JAXB implementation will automatically assign namespace 
prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you 
to refer to a map which contains the [...]
-    "xmlStreamWriterWrapper": { "index": 15, "kind": "attribute", 
"displayName": "Xml Stream Writer Wrapper", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "To use a custom xml stream writer." },
-    "schemaLocation": { "index": 16, "kind": "attribute", "displayName": 
"Schema Location", "group": "common", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "To define the location of the schema" },
-    "noNamespaceSchemaLocation": { "index": 17, "kind": "attribute", 
"displayName": "No Namespace Schema Location", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "To define the location of the namespaceless schema" },
-    "jaxbProviderProperties": { "index": 18, "kind": "attribute", 
"displayName": "Jaxb Provider Properties", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Refers to a custom java.util.Map to lookup in the registry 
containing custom JAXB provider properties to be used with the JAXB 
marshaller." },
-    "contentTypeHeader": { "index": 19, "kind": "attribute", "displayName": 
"Content Type Header", "group": "common", "required": false, "type": "boolean", 
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": true, "description": "Whether the data format 
should set the Content-Type header with the type from the data format. For 
example application\/xml for data formats marshalling to XML, or 
application\/json for data formats marshall [...]
-    "accessExternalSchemaProtocols": { "index": 20, "kind": "attribute", 
"displayName": "Access External Schema Protocols", "group": "security", 
"label": "security", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Only in use if schema validation has been enabled. Restrict 
access to the protocols specified for external reference set by the 
schemaLocation attribute, Import and Include element. E [...]
+    "allowPartClassFromHeader": { "index": 14, "kind": "attribute", 
"displayName": "Allow Part Class From Header", "group": "advanced", "label": 
"advanced", "required": false, "type": "boolean", "javaType": 
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": false, "description": "Whether the CamelJaxbPartClass and 
CamelJaxbPartNamespace headers are used, when set, instead of the partClass and 
partNamespace options when marshalling and unmarshal [...]
+    "namespacePrefix": { "index": 15, "kind": "attribute", "displayName": 
"Namespace Prefix", "group": "advanced", "label": "advanced", "required": 
false, "type": "object", "javaType": "java.util.Map", "deprecated": false, 
"autowired": false, "secret": false, "description": "When marshalling using 
JAXB or SOAP then the JAXB implementation will automatically assign namespace 
prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you 
to refer to a map which contains the [...]
+    "xmlStreamWriterWrapper": { "index": 16, "kind": "attribute", 
"displayName": "Xml Stream Writer Wrapper", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "To use a custom xml stream writer." },
+    "schemaLocation": { "index": 17, "kind": "attribute", "displayName": 
"Schema Location", "group": "common", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "To define the location of the schema" },
+    "noNamespaceSchemaLocation": { "index": 18, "kind": "attribute", 
"displayName": "No Namespace Schema Location", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "To define the location of the namespaceless schema" },
+    "jaxbProviderProperties": { "index": 19, "kind": "attribute", 
"displayName": "Jaxb Provider Properties", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Refers to a custom java.util.Map to lookup in the registry 
containing custom JAXB provider properties to be used with the JAXB 
marshaller." },
+    "contentTypeHeader": { "index": 20, "kind": "attribute", "displayName": 
"Content Type Header", "group": "common", "required": false, "type": "boolean", 
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": true, "description": "Whether the data format 
should set the Content-Type header with the type from the data format. For 
example application\/xml for data formats marshalling to XML, or 
application\/json for data formats marshall [...]
+    "accessExternalSchemaProtocols": { "index": 21, "kind": "attribute", 
"displayName": "Access External Schema Protocols", "group": "security", 
"label": "security", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Only in use if schema validation has been enabled. Restrict 
access to the protocols specified for external reference set by the 
schemaLocation attribute, Import and Include element. E [...]
   }
 }
diff --git a/components/camel-jaxb/src/main/docs/jaxb-dataformat.adoc 
b/components/camel-jaxb/src/main/docs/jaxb-dataformat.adoc
index aed39ed82b6c..c709b3d20424 100644
--- a/components/camel-jaxb/src/main/docs/jaxb-dataformat.adoc
+++ b/components/camel-jaxb/src/main/docs/jaxb-dataformat.adoc
@@ -95,24 +95,36 @@ need to unmarshall only part of the tree.
 
 In that case, you can use partial unmarshalling. To enable this
 behavior, you need set property `partClass` on the `JaxbDataFormat`. Camel 
will pass this class
-to the JAXB unmarshaller. If `JaxbConstants.JAXB_PART_CLASS` is set as
-one of the exchange headers, its value is used to override the `partClass` 
property
-on the `JaxbDataFormat`.
+to the JAXB unmarshaller.
 
 For marshalling you have to add the `partNamespace` attribute with the `QName` 
of
 the destination namespace.
 
-If `JaxbConstants.JAXB_PART_NAMESPACE` is set as
-one of the exchange headers, its value is used to override the `partNamespace` 
property
-on the `JaxbDataFormat`.
+==== Choosing the part class with headers
 
-While setting `partNamespace` through `JaxbConstants.JAXB_PART_NAMESPACE`, 
please
+To choose the part class and namespace per message, enable the 
`allowPartClassFromHeader` option
+(default `false`). Then the following exchange headers, when set, are used 
instead of the
+`partClass` and `partNamespace` options on the `JaxbDataFormat`:
+
+* `CamelJaxbPartClass`: the class name used instead of `partClass`, when 
marshalling and unmarshalling.
+* `CamelJaxbPartNamespace`: the namespace used instead of `partNamespace`, 
when marshalling.
+
+When `allowPartClassFromHeader` is `false`, these headers are ignored.
+
+While setting `partNamespace` through the `CamelJaxbPartNamespace` header, 
please
 note that you need to specify its value in the format 
`\{namespaceUri\}localPart`, as per the example below.
 
 [source,java]
---------------------------------------------------------------------------------------
-.setHeader(JaxbConstants.JAXB_PART_NAMESPACE, 
constant("{http://www.camel.apache.org/jaxb/example/address/1}address";));
---------------------------------------------------------------------------------------
+----
+JaxbDataFormat jaxb = new JaxbDataFormat("com.mycompany.model");
+jaxb.setAllowPartClassFromHeader(true);
+
+from("direct:start")
+    .setHeader("CamelJaxbPartClass", constant("com.mycompany.model.Address"))
+    .setHeader("CamelJaxbPartNamespace", 
constant("{http://www.camel.apache.org/jaxb/example/address/1}address";))
+    .marshal(jaxb)
+    .to("mock:result");
+----
 
 === Fragment
 
diff --git 
a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
 
b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
index 48def5c620a5..c6dfa101989f 100644
--- 
a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
+++ 
b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
@@ -99,6 +99,7 @@ public class JaxbDataFormat extends ServiceSupport
     // partial support
     private QName partNamespace;
     private Class<?> partClass;
+    private boolean allowPartClassFromHeader;
     private Map<String, String> namespacePrefix;
     private JaxbNamespacePrefixMapper namespacePrefixMapper;
     private JaxbXmlStreamWriterWrapper xmlStreamWriterWrapper;
@@ -189,8 +190,12 @@ public class JaxbDataFormat extends ServiceSupport
 
         Object element = graph;
         QName partNamespaceOnDataFormat = getPartNamespace();
-        String partClassFromHeader = 
exchange.getIn().getHeader(JaxbConstants.JAXB_PART_CLASS, String.class);
-        String partNamespaceFromHeader = 
exchange.getIn().getHeader(JaxbConstants.JAXB_PART_NAMESPACE, String.class);
+        String partClassFromHeader = null;
+        String partNamespaceFromHeader = null;
+        if (allowPartClassFromHeader) {
+            partClassFromHeader = 
exchange.getIn().getHeader(JaxbConstants.JAXB_PART_CLASS, String.class);
+            partNamespaceFromHeader = 
exchange.getIn().getHeader(JaxbConstants.JAXB_PART_NAMESPACE, String.class);
+        }
         if ((partClass != null || partClassFromHeader != null)
                 && (partNamespaceOnDataFormat != null || 
partNamespaceFromHeader != null)) {
             element = toElement(graph, partClassFromHeader, 
partNamespaceFromHeader, partNamespaceOnDataFormat);
@@ -290,9 +295,11 @@ public class JaxbDataFormat extends ServiceSupport
     private Object toElement(
             Object graph, String partClassFromHeader, String 
partNamespaceFromHeader, QName partNamespaceOnDataFormat)
             throws JAXBException {
+        Class<?> effectivePartClass = partClass;
         if (partClassFromHeader != null) {
             try {
-                partClass = 
camelContext.getClassResolver().resolveMandatoryClass(partClassFromHeader, 
Object.class);
+                effectivePartClass
+                        = 
camelContext.getClassResolver().resolveMandatoryClass(partClassFromHeader, 
Object.class);
             } catch (ClassNotFoundException e) {
                 throw new JAXBException(e);
             }
@@ -300,7 +307,7 @@ public class JaxbDataFormat extends ServiceSupport
         if (partNamespaceFromHeader != null) {
             partNamespaceOnDataFormat = QName.valueOf(partNamespaceFromHeader);
         }
-        return new JAXBElement<>(partNamespaceOnDataFormat, (Class<Object>) 
partClass, graph);
+        return new JAXBElement<>(partNamespaceOnDataFormat, (Class<Object>) 
effectivePartClass, graph);
     }
 
     private boolean asXmlStreamWriter(Exchange exchange) {
@@ -329,17 +336,19 @@ public class JaxbDataFormat extends ServiceSupport
                     xmlReader = typeConverter.convertTo(XMLStreamReader.class, 
exchange, is);
                 }
             }
-            String partClassFromHeader = 
exchange.getIn().getHeader(JaxbConstants.JAXB_PART_CLASS, String.class);
-            if (partClass != null || partClassFromHeader != null) {
-                // partial unmarshalling
-                if (partClassFromHeader != null) {
-                    try {
-                        partClass = 
camelContext.getClassResolver().resolveMandatoryClass(partClassFromHeader, 
Object.class);
-                    } catch (ClassNotFoundException e) {
-                        throw new JAXBException(e);
-                    }
+            String partClassFromHeader = allowPartClassFromHeader
+                    ? 
exchange.getIn().getHeader(JaxbConstants.JAXB_PART_CLASS, String.class) : null;
+            Class<?> effectivePartClass = partClass;
+            if (partClassFromHeader != null) {
+                try {
+                    effectivePartClass
+                            = 
camelContext.getClassResolver().resolveMandatoryClass(partClassFromHeader, 
Object.class);
+                } catch (ClassNotFoundException e) {
+                    throw new JAXBException(e);
                 }
-                answer = createUnmarshaller().unmarshal(xmlReader, partClass);
+            }
+            if (effectivePartClass != null) {
+                answer = createUnmarshaller().unmarshal(xmlReader, 
effectivePartClass);
             } else {
                 answer = createUnmarshaller().unmarshal(xmlReader);
             }
@@ -492,6 +501,18 @@ public class JaxbDataFormat extends ServiceSupport
         this.partClass = partClass;
     }
 
+    public boolean isAllowPartClassFromHeader() {
+        return allowPartClassFromHeader;
+    }
+
+    /**
+     * Whether the {@link JaxbConstants#JAXB_PART_CLASS} and {@link 
JaxbConstants#JAXB_PART_NAMESPACE} headers are used,
+     * when set, instead of the partClass and partNamespace options when 
marshalling and unmarshalling.
+     */
+    public void setAllowPartClassFromHeader(boolean allowPartClassFromHeader) {
+        this.allowPartClassFromHeader = allowPartClassFromHeader;
+    }
+
     public Map<String, String> getNamespacePrefix() {
         return namespacePrefix;
     }
diff --git 
a/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatPartClassHeaderTest.java
 
b/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatPartClassHeaderTest.java
index 0c224bf7a047..536c25047b02 100644
--- 
a/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatPartClassHeaderTest.java
+++ 
b/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatPartClassHeaderTest.java
@@ -75,6 +75,7 @@ public class JaxbDataFormatPartClassHeaderTest extends 
CamelTestSupport {
                 jaxbDataFormat.setPartNamespace(
                         new 
QName("http://www.camel.apache.org/jaxb/example/address/123";, 
"addressToBeOverriden"));
                 jaxbDataFormat.setPrettyPrint(true);
+                jaxbDataFormat.setAllowPartClassFromHeader(true);
 
                 from("direct:marshall")
                         .setHeader(JaxbConstants.JAXB_PART_CLASS, 
simple("org.apache.camel.example.Address"))
diff --git 
a/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbPartClassHeaderOptionTest.java
 
b/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbPartClassHeaderOptionTest.java
new file mode 100644
index 000000000000..3ab41f1acd41
--- /dev/null
+++ 
b/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbPartClassHeaderOptionTest.java
@@ -0,0 +1,124 @@
+/*
+ * 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.converter.jaxb;
+
+import javax.xml.namespace.QName;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.example.Address;
+import org.apache.camel.example.Partial;
+import org.apache.camel.example.PurchaseOrder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The CamelJaxbPartClass and CamelJaxbPartNamespace headers are used only 
when allowPartClassFromHeader is enabled.
+ */
+public class JaxbPartClassHeaderOptionTest extends CamelTestSupport {
+
+    private static final String ADDRESS_NAMESPACE = 
"http://www.camel.apache.org/jaxb/example/address/1";;
+
+    private static final String PARTIAL_XML = "<partial 
name=\"foo\"><location>Here</location></partial>";
+
+    private static final String PURCHASE_ORDER_XML = "<purchaseOrder 
name=\"foo\" price=\"1.23\" amount=\"2.0\"/>";
+
+    @Test
+    public void partClassHeaderIgnoredByDefault() {
+        Object body = template.requestBodyAndHeader("direct:unmarshal", 
PARTIAL_XML,
+                JaxbConstants.JAXB_PART_CLASS, Address.class.getName());
+
+        Partial partial = assertInstanceOf(Partial.class, body);
+        assertEquals("foo", partial.getName());
+        assertEquals("Here", partial.getLocation());
+    }
+
+    @Test
+    public void partClassHeaderUsedWhenAllowed() {
+        Object body = template.requestBodyAndHeader("direct:unmarshalAllowed", 
PARTIAL_XML,
+                JaxbConstants.JAXB_PART_CLASS, Address.class.getName());
+
+        assertInstanceOf(Address.class, body);
+    }
+
+    @Test
+    public void partClassHeaderAloneDoesNotEnablePartialUnmarshalByDefault() {
+        Object body = 
template.requestBodyAndHeader("direct:unmarshalNoPartClass", PURCHASE_ORDER_XML,
+                JaxbConstants.JAXB_PART_CLASS, Address.class.getName());
+
+        PurchaseOrder order = assertInstanceOf(PurchaseOrder.class, body);
+        assertEquals("foo", order.getName());
+    }
+
+    @Test
+    public void partNamespaceHeaderIgnoredByDefaultOnMarshal() {
+        String xml = template.requestBodyAndHeader("direct:marshal", 
createAddress(),
+                JaxbConstants.JAXB_PART_NAMESPACE, "{" + ADDRESS_NAMESPACE + 
"}shippingAddress", String.class);
+
+        assertTrue(xml.contains("<address:address"), xml);
+        assertFalse(xml.contains("shippingAddress"), xml);
+    }
+
+    @Test
+    public void partNamespaceHeaderUsedWhenAllowed() {
+        String xml = template.requestBodyAndHeader("direct:marshalAllowed", 
createAddress(),
+                JaxbConstants.JAXB_PART_NAMESPACE, "{" + ADDRESS_NAMESPACE + 
"}shippingAddress", String.class);
+
+        assertTrue(xml.contains("<address:shippingAddress"), xml);
+    }
+
+    private static Address createAddress() {
+        Address address = new Address();
+        address.setStreet("Main Street");
+        address.setStreetNumber("3a");
+        address.setZip("65843");
+        address.setCity("Sulzbach");
+        return address;
+    }
+
+    private static JaxbDataFormat createDataFormat(Class<?> partClass, boolean 
allowPartClassFromHeader) {
+        JaxbDataFormat jaxb = new JaxbDataFormat();
+        jaxb.setContextPath(Address.class.getPackage().getName());
+        jaxb.setPartClass(partClass);
+        jaxb.setAllowPartClassFromHeader(allowPartClassFromHeader);
+        return jaxb;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                
from("direct:unmarshal").unmarshal(createDataFormat(Partial.class, false));
+                
from("direct:unmarshalAllowed").unmarshal(createDataFormat(Partial.class, 
true));
+                
from("direct:unmarshalNoPartClass").unmarshal(createDataFormat(null, false));
+
+                JaxbDataFormat marshal = createDataFormat(Address.class, 
false);
+                marshal.setPartNamespace(new QName(ADDRESS_NAMESPACE, 
"address"));
+                from("direct:marshal").marshal(marshal);
+
+                JaxbDataFormat marshalAllowed = 
createDataFormat(Address.class, true);
+                marshalAllowed.setPartNamespace(new QName(ADDRESS_NAMESPACE, 
"address"));
+                from("direct:marshalAllowed").marshal(marshalAllowed);
+            }
+        };
+    }
+}
diff --git 
a/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbPartClassHeaderStatePollutionTest.java
 
b/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbPartClassHeaderStatePollutionTest.java
new file mode 100644
index 000000000000..a7aeca2c5c03
--- /dev/null
+++ 
b/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbPartClassHeaderStatePollutionTest.java
@@ -0,0 +1,142 @@
+/*
+ * 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.converter.jaxb;
+
+import java.util.Map;
+
+import jakarta.xml.bind.JAXBElement;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.example.Address;
+import org.apache.camel.example.PurchaseOrder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Verifies that a CamelJaxbPartClass header on one exchange does not 
permanently mutate the shared JaxbDataFormat
+ * instance, which would cause subsequent exchanges (without the header) to 
unmarshal/marshal using the leaked class.
+ *
+ * @see <a 
href="https://issues.apache.org/jira/browse/CAMEL-24164";>CAMEL-24164</a>
+ */
+public class JaxbPartClassHeaderStatePollutionTest extends CamelTestSupport {
+
+    private static final String PURCHASE_ORDER_XML
+            = "<purchaseOrder name=\"foo\" price=\"1.23\" amount=\"2.0\"/>";
+
+    private static final String ADDRESS_XML
+            = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
+              + "<address 
xmlns=\"http://www.camel.apache.org/jaxb/example/address/1\";>"
+              + "<street>Main Street</street>"
+              + "<streetNumber>3a</streetNumber>"
+              + "<zip>65843</zip>"
+              + "<city>Sulzbach</city>"
+              + "</address>";
+
+    @Test
+    void unmarshalPartClassHeaderDoesNotLeakToNextExchange() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:unmarshal");
+        mock.expectedMessageCount(2);
+
+        // Exchange 1: unmarshal with CamelJaxbPartClass header -> partial 
unmarshalling
+        template.sendBodyAndHeader("direct:unmarshal", ADDRESS_XML,
+                JaxbConstants.JAXB_PART_CLASS, 
"org.apache.camel.example.Address");
+
+        // Exchange 2: unmarshal WITHOUT header -> should use default (full) 
unmarshalling
+        template.sendBody("direct:unmarshal", PURCHASE_ORDER_XML);
+
+        MockEndpoint.assertIsSatisfied(context);
+
+        Object body1 = mock.getExchanges().get(0).getIn().getBody();
+        if (body1 instanceof JAXBElement) {
+            body1 = ((JAXBElement<?>) body1).getValue();
+        }
+        assertInstanceOf(Address.class, body1, "Exchange 1 should unmarshal as 
Address");
+
+        Object body2 = mock.getExchanges().get(1).getIn().getBody();
+        assertInstanceOf(PurchaseOrder.class, body2,
+                "Exchange 2 (no header) must NOT leak to Address — should 
unmarshal as PurchaseOrder");
+    }
+
+    @Test
+    void marshalPartClassHeaderDoesNotLeakToNextExchange() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:marshal");
+        mock.expectedMessageCount(2);
+
+        Address address = new Address();
+        address.setStreet("Main Street");
+        address.setStreetNumber("3a");
+        address.setZip("65843");
+        address.setCity("Sulzbach");
+
+        // Exchange 1: marshal with CamelJaxbPartClass + 
CamelJaxbPartNamespace headers
+        template.sendBodyAndHeaders("direct:marshal", address,
+                Map.of(
+                        JaxbConstants.JAXB_PART_CLASS, 
"org.apache.camel.example.Address",
+                        JaxbConstants.JAXB_PART_NAMESPACE,
+                        
"{http://www.camel.apache.org/jaxb/example/address/1}address";));
+
+        // Exchange 2: marshal a PurchaseOrder (has @XmlRootElement) WITHOUT 
headers
+        PurchaseOrder order = new PurchaseOrder();
+        order.setName("foo");
+        order.setPrice(1.23);
+        order.setAmount(2.0);
+        template.sendBody("direct:marshal", order);
+
+        MockEndpoint.assertIsSatisfied(context);
+
+        String payload1 = 
mock.getExchanges().get(0).getIn().getBody(String.class);
+        String payload2 = 
mock.getExchanges().get(1).getIn().getBody(String.class);
+
+        assertTrue(payload1.contains("<address:address"),
+                "Exchange 1 should use partial marshalling with the 
header-specified namespace");
+
+        assertFalse(payload2.contains("<address:address"),
+                "Exchange 2 (no header) must NOT leak partial marshalling from 
Exchange 1");
+        assertTrue(payload2.contains("<purchaseOrder"),
+                "Exchange 2 should marshal as a PurchaseOrder root element");
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                JaxbDataFormat jaxb = new JaxbDataFormat();
+                jaxb.setContextPath("org.apache.camel.example");
+                jaxb.setAllowPartClassFromHeader(true);
+
+                from("direct:unmarshal")
+                        .unmarshal(jaxb)
+                        .to("mock:unmarshal");
+
+                JaxbDataFormat jaxbMarshal = new JaxbDataFormat();
+                jaxbMarshal.setContextPath("org.apache.camel.example");
+                jaxbMarshal.setPrettyPrint(true);
+                jaxbMarshal.setAllowPartClassFromHeader(true);
+
+                from("direct:marshal")
+                        .marshal(jaxbMarshal)
+                        .to("mock:marshal");
+            }
+        };
+    }
+}
diff --git 
a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyNoContentRestConfigTest.java
 
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyNoContentRestConfigTest.java
index bad2a6b73535..44112fcad041 100644
--- 
a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyNoContentRestConfigTest.java
+++ 
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyNoContentRestConfigTest.java
@@ -140,7 +140,8 @@ public class RestJettyNoContentRestConfigTest extends 
BaseJettyTest {
             @Override
             public void configure() {
                 
restConfiguration().component("jetty").host("localhost").port(getPort())
-                        
.bindingMode(RestBindingMode.auto).enableNoContentResponse(true);
+                        
.bindingMode(RestBindingMode.auto).enableNoContentResponse(true)
+                        
.dataFormatProperty("xml.out.allowPartClassFromHeader", "true");
 
                 rest("/v1/empty")
                         .get("/country").to("direct:v1country")
diff --git 
a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyNoContentTest.java
 
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyNoContentTest.java
index 30acebbfc74a..40c097747368 100644
--- 
a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyNoContentTest.java
+++ 
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyNoContentTest.java
@@ -140,7 +140,8 @@ public class RestJettyNoContentTest extends BaseJettyTest {
             @Override
             public void configure() {
                 
restConfiguration().component("jetty").host("localhost").port(getPort())
-                        .bindingMode(RestBindingMode.auto);
+                        .bindingMode(RestBindingMode.auto)
+                        
.dataFormatProperty("xml.out.allowPartClassFromHeader", "true");
 
                 rest("/v1/empty")
                         .get("/country").to("direct:v1country")
diff --git 
a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletNoContentRestConfigTest.java
 
b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletNoContentRestConfigTest.java
index 78723c714759..2a05e63428bd 100644
--- 
a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletNoContentRestConfigTest.java
+++ 
b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletNoContentRestConfigTest.java
@@ -106,7 +106,8 @@ public class RestServletNoContentRestConfigTest extends 
ServletCamelRouterTestSu
             @Override
             public void configure() {
                 restConfiguration().component("servlet").host("localhost")
-                        
.bindingMode(RestBindingMode.auto).enableNoContentResponse(true);
+                        
.bindingMode(RestBindingMode.auto).enableNoContentResponse(true)
+                        
.dataFormatProperty("xml.out.allowPartClassFromHeader", "true");
 
                 rest("/v1/empty")
                         .get("/country").to("direct:v1country")
diff --git 
a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletNoContentTest.java
 
b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletNoContentTest.java
index 65ee18339a89..46cdcddbf500 100644
--- 
a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletNoContentTest.java
+++ 
b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletNoContentTest.java
@@ -105,7 +105,8 @@ public class RestServletNoContentTest extends 
ServletCamelRouterTestSupport {
             @Override
             public void configure() {
                 restConfiguration().component("servlet").host("localhost")
-                        .bindingMode(RestBindingMode.auto);
+                        .bindingMode(RestBindingMode.auto)
+                        
.dataFormatProperty("xml.out.allowPartClassFromHeader", "true");
 
                 rest("/v1/empty")
                         .get("/country").to("direct:v1country")
diff --git 
a/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java
 
b/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java
index 132e332b89fb..d2dfe2877731 100644
--- 
a/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java
+++ 
b/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java
@@ -18,6 +18,7 @@ package org.apache.camel.dataformat.soap;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Map;
 
 import jakarta.xml.ws.soap.SOAPFaultException;
 
@@ -28,6 +29,7 @@ import org.apache.camel.Produce;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.converter.jaxb.JaxbConstants;
 import org.apache.camel.test.junit5.CamelTestSupport;
 import org.junit.jupiter.api.Test;
 
@@ -60,6 +62,19 @@ public class SoapUnMarshalTest extends CamelTestSupport {
         assertEquals("Smith", request.getName());
     }
 
+    @Test
+    public void testUnMarshalSoapIgnoresPartClassHeaders() throws IOException, 
InterruptedException {
+        resultEndpoint.expectedMessageCount(1);
+        InputStream in = this.getClass().getResourceAsStream("request.xml");
+        producer.sendBodyAndHeaders(in, Map.of(
+                JaxbConstants.JAXB_PART_CLASS, 
GetCustomersByName.class.getName(),
+                JaxbConstants.JAXB_PART_NAMESPACE, 
"{http://customerservice.example.com/}getCustomersByName";));
+        resultEndpoint.assertIsSatisfied();
+        Object body = resultEndpoint.getExchanges().get(0).getIn().getBody();
+        assertEquals(GetCustomersByName.class, body.getClass());
+        assertEquals("Smith", ((GetCustomersByName) body).getName());
+    }
+
     @Test
     public void testUnMarshalSoapFaultWithoutDetail() throws IOException, 
InterruptedException {
         InputStream in = 
this.getClass().getResourceAsStream("faultWithoutDetail.xml");
diff --git 
a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/jaxb.json
 
b/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/jaxb.json
index e59e07fc6fc6..4f7f4aa67263 100644
--- 
a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/jaxb.json
+++ 
b/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/jaxb.json
@@ -27,12 +27,13 @@
     "fragment": { "index": 11, "kind": "attribute", "displayName": "Fragment", 
"group": "advanced", "label": "advanced", "required": false, "type": "boolean", 
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": false, "description": "To turn on marshalling 
XML fragment trees. By default JAXB looks for XmlRootElement annotation on 
given class to operate on whole XML tree. This is useful but not always - 
sometimes generated code does n [...]
     "partClass": { "index": 12, "kind": "attribute", "displayName": "Part 
Class", "group": "advanced", "label": "advanced", "required": false, "type": 
"string", "javaType": "java.lang.String", "deprecated": false, "autowired": 
false, "secret": false, "description": "Name of class used for fragment 
parsing. See more details at the fragment option." },
     "partNamespace": { "index": 13, "kind": "attribute", "displayName": "Part 
Namespace", "group": "advanced", "label": "advanced", "required": false, 
"type": "string", "javaType": "java.lang.String", "deprecated": false, 
"autowired": false, "secret": false, "description": "XML namespace to use for 
fragment parsing. See more details at the fragment option." },
-    "namespacePrefix": { "index": 14, "kind": "attribute", "displayName": 
"Namespace Prefix", "group": "advanced", "label": "advanced", "required": 
false, "type": "object", "javaType": "java.util.Map", "deprecated": false, 
"autowired": false, "secret": false, "description": "When marshalling using 
JAXB or SOAP then the JAXB implementation will automatically assign namespace 
prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you 
to refer to a map which contains the [...]
-    "xmlStreamWriterWrapper": { "index": 15, "kind": "attribute", 
"displayName": "Xml Stream Writer Wrapper", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "To use a custom xml stream writer." },
-    "schemaLocation": { "index": 16, "kind": "attribute", "displayName": 
"Schema Location", "group": "common", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "To define the location of the schema" },
-    "noNamespaceSchemaLocation": { "index": 17, "kind": "attribute", 
"displayName": "No Namespace Schema Location", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "To define the location of the namespaceless schema" },
-    "jaxbProviderProperties": { "index": 18, "kind": "attribute", 
"displayName": "Jaxb Provider Properties", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Refers to a custom java.util.Map to lookup in the registry 
containing custom JAXB provider properties to be used with the JAXB 
marshaller." },
-    "contentTypeHeader": { "index": 19, "kind": "attribute", "displayName": 
"Content Type Header", "group": "common", "required": false, "type": "boolean", 
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": true, "description": "Whether the data format 
should set the Content-Type header with the type from the data format. For 
example application\/xml for data formats marshalling to XML, or 
application\/json for data formats marshall [...]
-    "accessExternalSchemaProtocols": { "index": 20, "kind": "attribute", 
"displayName": "Access External Schema Protocols", "group": "security", 
"label": "security", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Only in use if schema validation has been enabled. Restrict 
access to the protocols specified for external reference set by the 
schemaLocation attribute, Import and Include element. E [...]
+    "allowPartClassFromHeader": { "index": 14, "kind": "attribute", 
"displayName": "Allow Part Class From Header", "group": "advanced", "label": 
"advanced", "required": false, "type": "boolean", "javaType": 
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": false, "description": "Whether the CamelJaxbPartClass and 
CamelJaxbPartNamespace headers are used, when set, instead of the partClass and 
partNamespace options when marshalling and unmarshal [...]
+    "namespacePrefix": { "index": 15, "kind": "attribute", "displayName": 
"Namespace Prefix", "group": "advanced", "label": "advanced", "required": 
false, "type": "object", "javaType": "java.util.Map", "deprecated": false, 
"autowired": false, "secret": false, "description": "When marshalling using 
JAXB or SOAP then the JAXB implementation will automatically assign namespace 
prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you 
to refer to a map which contains the [...]
+    "xmlStreamWriterWrapper": { "index": 16, "kind": "attribute", 
"displayName": "Xml Stream Writer Wrapper", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "To use a custom xml stream writer." },
+    "schemaLocation": { "index": 17, "kind": "attribute", "displayName": 
"Schema Location", "group": "common", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "To define the location of the schema" },
+    "noNamespaceSchemaLocation": { "index": 18, "kind": "attribute", 
"displayName": "No Namespace Schema Location", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "To define the location of the namespaceless schema" },
+    "jaxbProviderProperties": { "index": 19, "kind": "attribute", 
"displayName": "Jaxb Provider Properties", "group": "advanced", "label": 
"advanced", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Refers to a custom java.util.Map to lookup in the registry 
containing custom JAXB provider properties to be used with the JAXB 
marshaller." },
+    "contentTypeHeader": { "index": 20, "kind": "attribute", "displayName": 
"Content Type Header", "group": "common", "required": false, "type": "boolean", 
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": true, "description": "Whether the data format 
should set the Content-Type header with the type from the data format. For 
example application\/xml for data formats marshalling to XML, or 
application\/json for data formats marshall [...]
+    "accessExternalSchemaProtocols": { "index": 21, "kind": "attribute", 
"displayName": "Access External Schema Protocols", "group": "security", 
"label": "security", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Only in use if schema validation has been enabled. Restrict 
access to the protocols specified for external reference set by the 
schemaLocation attribute, Import and Include element. E [...]
   }
 }
diff --git 
a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
 
b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
index 5909248d6e06..217bc6d9d1a9 100644
--- 
a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
+++ 
b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
@@ -72,6 +72,9 @@ public class JaxbDataFormat extends DataFormatDefinition 
implements ContentTypeH
     @Metadata(label = "advanced")
     private String partNamespace;
     @XmlAttribute
+    @Metadata(label = "advanced", javaType = "java.lang.Boolean")
+    private String allowPartClassFromHeader;
+    @XmlAttribute
     @Metadata(label = "advanced", javaType = "java.util.Map")
     private String namespacePrefix;
     @XmlAttribute
@@ -113,6 +116,7 @@ public class JaxbDataFormat extends DataFormatDefinition 
implements ContentTypeH
         this.fragment = source.fragment;
         this.partClass = source.partClass;
         this.partNamespace = source.partNamespace;
+        this.allowPartClassFromHeader = source.allowPartClassFromHeader;
         this.namespacePrefix = source.namespacePrefix;
         this.xmlStreamWriterWrapper = source.xmlStreamWriterWrapper;
         this.schemaLocation = source.schemaLocation;
@@ -142,6 +146,7 @@ public class JaxbDataFormat extends DataFormatDefinition 
implements ContentTypeH
         this.fragment = builder.fragment;
         this.partClass = builder.partClass;
         this.partNamespace = builder.partNamespace;
+        this.allowPartClassFromHeader = builder.allowPartClassFromHeader;
         this.namespacePrefix = builder.namespacePrefix;
         this.xmlStreamWriterWrapper = builder.xmlStreamWriterWrapper;
         this.schemaLocation = builder.schemaLocation;
@@ -314,6 +319,19 @@ public class JaxbDataFormat extends DataFormatDefinition 
implements ContentTypeH
         this.partNamespace = partNamespace;
     }
 
+    public String getAllowPartClassFromHeader() {
+        return allowPartClassFromHeader;
+    }
+
+    /**
+     * Whether the CamelJaxbPartClass and CamelJaxbPartNamespace headers are 
used, when set, instead of the partClass
+     * and partNamespace options when marshalling and unmarshalling. Enable it 
only when the route sets these headers
+     * itself, not on routes that receive them from external systems.
+     */
+    public void setAllowPartClassFromHeader(String allowPartClassFromHeader) {
+        this.allowPartClassFromHeader = allowPartClassFromHeader;
+    }
+
     public String getNamespacePrefix() {
         return namespacePrefix;
     }
@@ -416,6 +434,7 @@ public class JaxbDataFormat extends DataFormatDefinition 
implements ContentTypeH
         private String fragment;
         private String partClass;
         private String partNamespace;
+        private String allowPartClassFromHeader;
         private String namespacePrefix;
         private String xmlStreamWriterWrapper;
         private String schemaLocation;
@@ -619,6 +638,26 @@ public class JaxbDataFormat extends DataFormatDefinition 
implements ContentTypeH
             return this;
         }
 
+        /**
+         * Whether the CamelJaxbPartClass and CamelJaxbPartNamespace headers 
are used, when set, instead of the
+         * partClass and partNamespace options when marshalling and 
unmarshalling. Enable it only when the route sets
+         * these headers itself, not on routes that receive them from external 
systems.
+         */
+        public Builder allowPartClassFromHeader(String 
allowPartClassFromHeader) {
+            this.allowPartClassFromHeader = allowPartClassFromHeader;
+            return this;
+        }
+
+        /**
+         * Whether the CamelJaxbPartClass and CamelJaxbPartNamespace headers 
are used, when set, instead of the
+         * partClass and partNamespace options when marshalling and 
unmarshalling. Enable it only when the route sets
+         * these headers itself, not on routes that receive them from external 
systems.
+         */
+        public Builder allowPartClassFromHeader(boolean 
allowPartClassFromHeader) {
+            this.allowPartClassFromHeader = 
Boolean.toString(allowPartClassFromHeader);
+            return this;
+        }
+
         /**
          * When marshalling using JAXB or SOAP then the JAXB implementation 
will automatically assign namespace
          * prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel 
allows you to refer to a map which
diff --git 
a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/JaxbDataFormatReifier.java
 
b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/JaxbDataFormatReifier.java
index 7bd50abbdf04..3eb6f4b27aee 100644
--- 
a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/JaxbDataFormatReifier.java
+++ 
b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/JaxbDataFormatReifier.java
@@ -40,6 +40,7 @@ public class JaxbDataFormatReifier extends 
DataFormatReifier<JaxbDataFormat> {
         properties.put("contextPathIsClassName", 
definition.getContextPathIsClassName());
         properties.put("partClass", definition.getPartClass());
         properties.put("partNamespace", definition.getPartNamespace());
+        properties.put("allowPartClassFromHeader", 
definition.getAllowPartClassFromHeader());
         properties.put("encoding", definition.getEncoding());
         properties.put("namespacePrefix", 
asRef(definition.getNamespacePrefix()));
         properties.put("schema", definition.getSchema());
diff --git 
a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java 
b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java
index 5382e45188cf..6c83edbaec82 100644
--- 
a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java
+++ 
b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java
@@ -2009,6 +2009,7 @@ public class ModelParser extends BaseParser {
     protected JaxbDataFormat doParseJaxbDataFormat() throws IOException, 
XmlPullParserException {
         return doParse(new JaxbDataFormat(), (def, key, val) -> switch (key) {
                 case "accessExternalSchemaProtocols": 
def.setAccessExternalSchemaProtocols(val); yield true;
+                case "allowPartClassFromHeader": 
def.setAllowPartClassFromHeader(val); yield true;
                 case "contentTypeHeader": def.setContentTypeHeader(val); yield 
true;
                 case "contextPath": def.setContextPath(val); yield true;
                 case "contextPathIsClassName": 
def.setContextPathIsClassName(val); yield true;
diff --git 
a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java
 
b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java
index e705bdda117e..34baab01d153 100644
--- 
a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java
+++ 
b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java
@@ -2739,6 +2739,7 @@ public class ModelWriter extends BaseWriter {
         doWriteAttribute("noNamespaceSchemaLocation", 
def.getNoNamespaceSchemaLocation(), null);
         doWriteAttribute("encoding", def.getEncoding(), null);
         doWriteAttribute("namespacePrefix", def.getNamespacePrefix(), null);
+        doWriteAttribute("allowPartClassFromHeader", 
def.getAllowPartClassFromHeader(), null);
         doWriteAttribute("fragment", def.getFragment(), null);
         doWriteAttribute("filterNonXmlChars", def.getFilterNonXmlChars(), 
null);
         doWriteAttribute("mustBeJAXBElement", def.getMustBeJAXBElement(), 
null);
diff --git 
a/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java
 
b/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java
index 970e347a27c3..fcbbd58402c4 100644
--- 
a/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java
+++ 
b/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java
@@ -2739,6 +2739,7 @@ public class ModelWriter extends BaseWriter {
         doWriteAttribute("noNamespaceSchemaLocation", 
def.getNoNamespaceSchemaLocation(), null);
         doWriteAttribute("encoding", def.getEncoding(), null);
         doWriteAttribute("namespacePrefix", def.getNamespacePrefix(), null);
+        doWriteAttribute("allowPartClassFromHeader", 
def.getAllowPartClassFromHeader(), null);
         doWriteAttribute("fragment", def.getFragment(), null);
         doWriteAttribute("filterNonXmlChars", def.getFilterNonXmlChars(), 
null);
         doWriteAttribute("mustBeJAXBElement", def.getMustBeJAXBElement(), 
null);
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java
index a0da686c8b19..aa856bb0a61a 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java
@@ -8177,6 +8177,7 @@ public final class ModelDeserializers extends 
YamlDeserializerSupport {
             deprecated = false,
             properties = {
                     @YamlProperty(name = "accessExternalSchemaProtocols", type 
= "string", description = "Only in use if schema validation has been enabled. 
Restrict access to the protocols specified for external reference set by the 
schemaLocation attribute, Import and Include element. Examples of protocols are 
file, http, jar:file. empty, false or none to deny all access to external 
references; a specific protocol, such as file, to give permission to only the 
protocol; the keyword all  [...]
+                    @YamlProperty(name = "allowPartClassFromHeader", type = 
"boolean", defaultValue = "false", description = "Whether the 
CamelJaxbPartClass and CamelJaxbPartNamespace headers are used, when set, 
instead of the partClass and partNamespace options when marshalling and 
unmarshalling. Enable it only when the route sets these headers itself, not on 
routes that receive them from external systems.", displayName = "Allow Part 
Class From Header"),
                     @YamlProperty(name = "contentTypeHeader", type = 
"boolean", defaultValue = "true", description = "Whether the data format should 
set the Content-Type header with the type from the data format. For example 
application/xml for data formats marshalling to XML, or application/json for 
data formats marshalling to JSON", displayName = "Content Type Header"),
                     @YamlProperty(name = "contextPath", type = "string", 
required = true, description = "Package name where your JAXB classes are 
located.", displayName = "Context Path"),
                     @YamlProperty(name = "contextPathIsClassName", type = 
"boolean", defaultValue = "false", description = "This can be set to true to 
mark that the contextPath is referring to a classname and not a package name.", 
displayName = "Context Path Is Class Name"),
@@ -8219,6 +8220,11 @@ public final class ModelDeserializers extends 
YamlDeserializerSupport {
                     target.setAccessExternalSchemaProtocols(val);
                     break;
                 }
+                case "allowPartClassFromHeader": {
+                    String val = asText(node);
+                    target.setAllowPartClassFromHeader(val);
+                    break;
+                }
                 case "contentTypeHeader": {
                     String val = asText(node);
                     target.setContentTypeHeader(val);
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json
index 856259e88996..9e8eed087d0f 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json
@@ -12044,6 +12044,12 @@
             "title" : "Access External Schema Protocols",
             "description" : "Only in use if schema validation has been 
enabled. Restrict access to the protocols specified for external reference set 
by the schemaLocation attribute, Import and Include element. Examples of 
protocols are file, http, jar:file. empty, false or none to deny all access to 
external references; a specific protocol, such as file, to give permission to 
only the protocol; the keyword all to grant permission to all protocols."
           },
+          "allowPartClassFromHeader" : {
+            "type" : "boolean",
+            "title" : "Allow Part Class From Header",
+            "description" : "Whether the CamelJaxbPartClass and 
CamelJaxbPartNamespace headers are used, when set, instead of the partClass and 
partNamespace options when marshalling and unmarshalling. Enable it only when 
the route sets these headers itself, not on routes that receive them from 
external systems.",
+            "default" : false
+          },
           "contentTypeHeader" : {
             "type" : "boolean",
             "title" : "Content Type Header",

Reply via email to