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 f8036a4c9354 CAMEL-27052: camel-jaxb - the part class and namespace 
headers are used only when allowPartClassFromHeader is enabled (#30212)
f8036a4c9354 is described below

commit f8036a4c935488138414bdc53d575aa4c4208d4b
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Nov 18 21:03:37 2026 +0100

    CAMEL-27052: camel-jaxb - the part class and namespace headers are used 
only when allowPartClassFromHeader is enabled (#30212)
    
    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; it has no such option, as a part
      class from a header always fails there with "Expected Soap Envelope".
    - The Rest DSL binding does not take allowPartClassFromHeader from the JAXB 
data format on the CamelContext (it is in
      RestBindingAdviceFactory.NOT_INHERITED_OPTIONS, next to partClass); set 
it with the xml.in./xml.out. data format
      property when the binding needs it.
    - Docs, the 4.24 upgrade guide and the regenerated metadata, catalog and 
DSL parsers and schemas.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../org/apache/camel/catalog/dataformats/jaxb.json |  15 +--
 .../apache/camel/catalog/docs/jaxb-dataformat.adoc |  26 +++--
 .../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 ++
 .../camel/catalog/schemas/camelYamlDsl-model.json  |  25 +++--
 .../converter/jaxb/JaxbDataFormatConfigurer.java   |   7 ++
 .../org/apache/camel/converter/jaxb/jaxb.json      |  15 +--
 .../camel-jaxb/src/main/docs/jaxb-dataformat.adoc  |  26 +++--
 .../camel/converter/jaxb/JaxbDataFormat.java       |  24 +++-
 .../jaxb/JaxbDataFormatPartClassHeaderTest.java    |   1 +
 .../jaxb/JaxbPartClassHeaderOptionTest.java        | 124 +++++++++++++++++++++
 .../JaxbPartClassHeaderStatePollutionTest.java     |   2 +
 .../jaxb/JaxbRestBindingPartClassTest.java         |  18 ++-
 .../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     |  38 +++++++
 .../reifier/dataformat/JaxbDataFormatReifier.java  |   1 +
 .../apache/camel/java/out/JavaDslModelWriter.java  |   1 +
 .../processor/RestBindingAdviceFactory.java        |   2 +-
 .../java/org/apache/camel/xml/in/ModelParser.java  |   1 +
 .../java/org/apache/camel/xml/out/ModelWriter.java |   1 +
 .../org/apache/camel/yaml/out/YamlModelWriter.java |   1 +
 .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc    |  22 +++-
 .../modules/ROOT/pages/rest-dsl-binding.adoc       |   6 +-
 .../dsl/yaml/deserializers/ModelDeserializers.java |   6 +
 .../resources/schema/camelYamlDsl-canonical.json   |   6 +
 .../resources/schema/camelYamlDsl-model.json       |  25 +++--
 .../generated/resources/schema/camelYamlDsl.json   |   6 +
 33 files changed, 406 insertions(+), 72 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 fad3db82ccdf..8cd225e4f9a6 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
@@ -36,12 +36,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 omit the XML 
declaration when marshalling, by setting the JAXB_FRAGMENT property on the JAXB 
marshaller. To marshal or unmarshal only part of the tree, or classes without 
the XmlRootElement annotation [...]
     "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." },
     "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." },
-    "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 set the xsi:schemaLocation attribute in the 
marshalled XML. This does not validate the XML; use the schema option to 
validate." },
-    "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." }
+    "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 set the xsi:schemaLocation attribute in the 
marshalled XML. This does not validate the XML; use the schema option to 
validate." },
+    "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." }
   }
 }
diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jaxb-dataformat.adoc
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jaxb-dataformat.adoc
index b32e36b186d9..fb7596951a8b 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jaxb-dataformat.adoc
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jaxb-dataformat.adoc
@@ -151,23 +151,35 @@ 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 `CamelJaxbPartClass` 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 `CamelJaxbPartNamespace` 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
+
+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("CamelJaxbPartNamespace", 
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/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 bc3edfcb7ea0..68af5bbf540a 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 omit the XML 
declaration when marshalling, by setting the JAXB_FRAGMENT property on the JAXB 
marshaller. To marshal or unmarshal only part of the tree, or classes without 
the XmlRootElement annotation [...]
     "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." },
     "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." },
-    "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 set the xsi:schemaLocation attribute in the 
marshalled XML. This does not validate the XML; use the schema option to 
validate." },
-    "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." }
+    "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 set the xsi:schemaLocation attribute in the 
marshalled XML. This does not validate the XML; use the schema option to 
validate." },
+    "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." }
   }
 }
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 bf10cf6aa43e..d660a2a0a239 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
@@ -9109,6 +9109,17 @@ Name of class used for fragment parsing.
             <xs:documentation xml:lang="en">
 <![CDATA[
 XML namespace to use for fragment parsing.
+]]>
+            </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 9cec60200983..458cd73f1921 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
@@ -8228,6 +8228,17 @@ Name of class used for fragment parsing.
             <xs:documentation xml:lang="en">
 <![CDATA[
 XML namespace to use for fragment parsing.
+]]>
+            </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/camelYamlDsl-model.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camelYamlDsl-model.json
index ea8a0380020d..3a409d7865bb 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camelYamlDsl-model.json
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camelYamlDsl-model.json
@@ -12422,6 +12422,17 @@
         "index" : 13,
         "group" : "advanced",
         "label" : "advanced"
+      }, {
+        "name" : "allowPartClassFromHeader",
+        "type" : "boolean",
+        "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.",
+        "title" : "Allow Part Class From Header",
+        "default" : "false",
+        "displayName" : "Allow Part Class From Header",
+        "kind" : "attribute",
+        "index" : 14,
+        "group" : "advanced",
+        "label" : "advanced"
       }, {
         "name" : "namespacePrefix",
         "type" : "string",
@@ -12429,7 +12440,7 @@
         "title" : "Namespace Prefix",
         "displayName" : "Namespace Prefix",
         "kind" : "attribute",
-        "index" : 14,
+        "index" : 15,
         "group" : "advanced",
         "label" : "advanced"
       }, {
@@ -12439,7 +12450,7 @@
         "title" : "Xml Stream Writer Wrapper",
         "displayName" : "Xml Stream Writer Wrapper",
         "kind" : "attribute",
-        "index" : 15,
+        "index" : 16,
         "group" : "advanced",
         "label" : "advanced"
       }, {
@@ -12449,7 +12460,7 @@
         "title" : "Schema Location",
         "displayName" : "Schema Location",
         "kind" : "attribute",
-        "index" : 16,
+        "index" : 17,
         "group" : "common"
       }, {
         "name" : "noNamespaceSchemaLocation",
@@ -12458,7 +12469,7 @@
         "title" : "No Namespace Schema Location",
         "displayName" : "No Namespace Schema Location",
         "kind" : "attribute",
-        "index" : 17,
+        "index" : 18,
         "group" : "advanced",
         "label" : "advanced"
       }, {
@@ -12468,7 +12479,7 @@
         "title" : "Jaxb Provider Properties",
         "displayName" : "Jaxb Provider Properties",
         "kind" : "attribute",
-        "index" : 18,
+        "index" : 19,
         "group" : "advanced",
         "label" : "advanced"
       }, {
@@ -12479,7 +12490,7 @@
         "default" : "true",
         "displayName" : "Content Type Header",
         "kind" : "attribute",
-        "index" : 19,
+        "index" : 20,
         "group" : "common"
       }, {
         "name" : "accessExternalSchemaProtocols",
@@ -12488,7 +12499,7 @@
         "title" : "Access External Schema Protocols",
         "displayName" : "Access External Schema Protocols",
         "kind" : "attribute",
-        "index" : 20,
+        "index" : 21,
         "group" : "security",
         "label" : "security"
       } ]
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 d19de33be9ab..63aee991e74f 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
@@ -24,6 +24,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);
@@ -52,6 +53,8 @@ public class JaxbDataFormatConfigurer extends 
org.apache.camel.support.component
         switch (ignoreCase ? name.toLowerCase(Locale.ROOT) : 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":
@@ -101,6 +104,8 @@ public class JaxbDataFormatConfigurer extends 
org.apache.camel.support.component
         switch (ignoreCase ? name.toLowerCase(Locale.ROOT) : 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":
@@ -146,6 +151,8 @@ public class JaxbDataFormatConfigurer extends 
org.apache.camel.support.component
         switch (ignoreCase ? name.toLowerCase(Locale.ROOT) : 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 fad3db82ccdf..8cd225e4f9a6 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
@@ -36,12 +36,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 omit the XML 
declaration when marshalling, by setting the JAXB_FRAGMENT property on the JAXB 
marshaller. To marshal or unmarshal only part of the tree, or classes without 
the XmlRootElement annotation [...]
     "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." },
     "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." },
-    "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 set the xsi:schemaLocation attribute in the 
marshalled XML. This does not validate the XML; use the schema option to 
validate." },
-    "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." }
+    "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 set the xsi:schemaLocation attribute in the 
marshalled XML. This does not validate the XML; use the schema option to 
validate." },
+    "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." }
   }
 }
diff --git a/components/camel-jaxb/src/main/docs/jaxb-dataformat.adoc 
b/components/camel-jaxb/src/main/docs/jaxb-dataformat.adoc
index b32e36b186d9..fb7596951a8b 100644
--- a/components/camel-jaxb/src/main/docs/jaxb-dataformat.adoc
+++ b/components/camel-jaxb/src/main/docs/jaxb-dataformat.adoc
@@ -151,23 +151,35 @@ 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 `CamelJaxbPartClass` 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 `CamelJaxbPartNamespace` 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
+
+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("CamelJaxbPartNamespace", 
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 0269dbc465fd..ecb6358db747 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
@@ -121,6 +121,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;
@@ -211,8 +212,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);
@@ -353,7 +358,8 @@ public class JaxbDataFormat extends ServiceSupport
                     xmlReader = typeConverter.convertTo(XMLStreamReader.class, 
exchange, is);
                 }
             }
-            String partClassFromHeader = 
exchange.getIn().getHeader(JaxbConstants.JAXB_PART_CLASS, String.class);
+            String partClassFromHeader = allowPartClassFromHeader
+                    ? 
exchange.getIn().getHeader(JaxbConstants.JAXB_PART_CLASS, String.class) : null;
             Class<?> effectivePartClass = partClass;
             if (partClassFromHeader != null) {
                 try {
@@ -517,6 +523,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 b2621ca746e9..d873054607c6 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..a81639e7a281
--- /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.junit6.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
index c7cc52270011..6b5030e39019 100644
--- 
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
@@ -122,6 +122,7 @@ public class JaxbPartClassHeaderStatePollutionTest extends 
CamelTestSupport {
             public void configure() {
                 JaxbDataFormat jaxb = new JaxbDataFormat();
                 jaxb.setContextPath("org.apache.camel.example");
+                jaxb.setAllowPartClassFromHeader(true);
 
                 from("direct:unmarshal")
                         .unmarshal(jaxb)
@@ -130,6 +131,7 @@ public class JaxbPartClassHeaderStatePollutionTest extends 
CamelTestSupport {
                 JaxbDataFormat jaxbMarshal = new JaxbDataFormat();
                 jaxbMarshal.setContextPath("org.apache.camel.example");
                 jaxbMarshal.setPrettyPrint(true);
+                jaxbMarshal.setAllowPartClassFromHeader(true);
 
                 from("direct:marshal")
                         .marshal(jaxbMarshal)
diff --git 
a/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbRestBindingPartClassTest.java
 
b/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbRestBindingPartClassTest.java
index 662365de4e9f..8ca4c30d46d0 100644
--- 
a/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbRestBindingPartClassTest.java
+++ 
b/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbRestBindingPartClassTest.java
@@ -34,8 +34,9 @@ import org.junit.jupiter.api.Test;
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 
 /**
- * The partClass of the jaxb data format configured on the context (such as 
with camel.dataformat.jaxb.part-class in
- * Camel Main) does not apply to the REST DSL binding, where the type of the 
verb decides the body type.
+ * The partClass and allowPartClassFromHeader of the jaxb data format 
configured on the context (such as with
+ * camel.dataformat.jaxb.part-class in Camel Main) do not apply to the REST 
DSL binding, where the type of the verb
+ * decides the body type.
  */
 public class JaxbRestBindingPartClassTest extends CamelTestSupport {
 
@@ -45,6 +46,7 @@ public class JaxbRestBindingPartClassTest extends 
CamelTestSupport {
         context.getRegistry().bind("direct-rest", new 
DirectRestConsumerFactory());
         JaxbDataFormat jaxb = (JaxbDataFormat) 
context.resolveDataFormat("jaxb");
         jaxb.setPartClass(Bar.class);
+        jaxb.setAllowPartClassFromHeader(true);
         return context;
     }
 
@@ -59,6 +61,18 @@ public class JaxbRestBindingPartClassTest extends 
CamelTestSupport {
         assertInstanceOf(PurchaseOrder.class, 
posted.getReceivedExchanges().get(0).getMessage().getBody());
     }
 
+    @Test
+    void restBindingDoesNotTakeAllowPartClassFromHeader() throws Exception {
+        MockEndpoint posted = getMockEndpoint("mock:posted");
+        posted.expectedMessageCount(1);
+
+        template.requestBodyAndHeader("direct:post-order", "<purchaseOrder 
name=\"foo\" price=\"1.23\" amount=\"2.0\"/>",
+                JaxbConstants.JAXB_PART_CLASS, Bar.class.getName());
+
+        posted.assertIsSatisfied();
+        assertInstanceOf(PurchaseOrder.class, 
posted.getReceivedExchanges().get(0).getMessage().getBody());
+    }
+
     @Override
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
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 c64fe51bf487..6b04a5f9194d 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
@@ -144,7 +144,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 f09db0ec341e..2677bba226d1 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
@@ -144,7 +144,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 fef517bd58f6..3973799e7141 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
@@ -108,7 +108,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 de503ae1dcfe..404576430037 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
@@ -108,7 +108,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 56123d74cf09..e790694fb7a7 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.junit6.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 bc3edfcb7ea0..68af5bbf540a 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 omit the XML 
declaration when marshalling, by setting the JAXB_FRAGMENT property on the JAXB 
marshaller. To marshal or unmarshal only part of the tree, or classes without 
the XmlRootElement annotation [...]
     "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." },
     "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." },
-    "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 set the xsi:schemaLocation attribute in the 
marshalled XML. This does not validate the XML; use the schema option to 
validate." },
-    "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." }
+    "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 set the xsi:schemaLocation attribute in the 
marshalled XML. This does not validate the XML; use the schema option to 
validate." },
+    "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." }
   }
 }
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 481f18372e6d..67ee25c538fa 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
@@ -92,6 +92,13 @@ public class JaxbDataFormat extends DataFormatDefinition 
implements ContentTypeH
     @Metadata(label = "advanced", description = "XML namespace to use for 
fragment parsing.")
     private String partNamespace;
     @XmlAttribute
+    @Metadata(label = "advanced", javaType = "java.lang.Boolean",
+              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.")
+    private String allowPartClassFromHeader;
+    @XmlAttribute
     @Metadata(label = "advanced", javaType = "java.util.Map",
               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 desired 
mapping.")
@@ -140,6 +147,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;
@@ -169,6 +177,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;
@@ -287,6 +296,14 @@ public class JaxbDataFormat extends DataFormatDefinition 
implements ContentTypeH
         this.partNamespace = partNamespace;
     }
 
+    public String getAllowPartClassFromHeader() {
+        return allowPartClassFromHeader;
+    }
+
+    public void setAllowPartClassFromHeader(String allowPartClassFromHeader) {
+        this.allowPartClassFromHeader = allowPartClassFromHeader;
+    }
+
     public String getNamespacePrefix() {
         return namespacePrefix;
     }
@@ -362,6 +379,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;
@@ -564,6 +582,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-java-io/src/generated/java/org/apache/camel/java/out/JavaDslModelWriter.java
 
b/core/camel-java-io/src/generated/java/org/apache/camel/java/out/JavaDslModelWriter.java
index 0ef1fde6ab6a..e3ad73bd4e96 100644
--- 
a/core/camel-java-io/src/generated/java/org/apache/camel/java/out/JavaDslModelWriter.java
+++ 
b/core/camel-java-io/src/generated/java/org/apache/camel/java/out/JavaDslModelWriter.java
@@ -3174,6 +3174,7 @@ public class JavaDslModelWriter extends 
JavaDslModelWriterSupport {
         doWriteAttribute(sb, "fragment", def.getFragment(), null);
         doWriteAttribute(sb, "partClass", def.getPartClass(), null);
         doWriteAttribute(sb, "partNamespace", def.getPartNamespace(), null);
+        doWriteAttribute(sb, "allowPartClassFromHeader", 
def.getAllowPartClassFromHeader(), null);
         doWriteAttribute(sb, "namespacePrefix", def.getNamespacePrefix(), 
null);
         doWriteAttribute(sb, "xmlStreamWriterWrapper", 
def.getXmlStreamWriterWrapper(), null);
         doWriteAttribute(sb, "schemaLocation", def.getSchemaLocation(), null);
diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/processor/RestBindingAdviceFactory.java
 
b/core/camel-support/src/main/java/org/apache/camel/support/processor/RestBindingAdviceFactory.java
index ee5f003197ea..06eead3cc321 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/processor/RestBindingAdviceFactory.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/processor/RestBindingAdviceFactory.java
@@ -55,7 +55,7 @@ public class RestBindingAdviceFactory {
     // type comes from the type and outType of the verb, not from a header or 
the options of the data format
     private static final Set<String> NOT_INHERITED_OPTIONS
             = Set.of("objectmapper", "xmlmapper", "allowunmarshalltype", 
"allowjmstype", "unmarshaltype", "uselist",
-                    "collectiontype", "partclass");
+                    "collectiontype", "partclass", "allowpartclassfromheader");
 
     /**
      * Builds the {@link RestBindingAdvice} from the given configuration
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 f305c9d2840b..7b8614f4d29e 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
@@ -1894,6 +1894,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 b56118335125..e4e4af6867e9 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
@@ -2532,6 +2532,7 @@ public class ModelWriter extends BaseWriter {
         doWriteAttribute("fragment", def.getFragment(), null);
         doWriteAttribute("partClass", def.getPartClass(), null);
         doWriteAttribute("partNamespace", def.getPartNamespace(), null);
+        doWriteAttribute("allowPartClassFromHeader", 
def.getAllowPartClassFromHeader(), null);
         doWriteAttribute("namespacePrefix", def.getNamespacePrefix(), null);
         doWriteAttribute("xmlStreamWriterWrapper", 
def.getXmlStreamWriterWrapper(), null);
         doWriteAttribute("schemaLocation", def.getSchemaLocation(), null);
diff --git 
a/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/YamlModelWriter.java
 
b/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/YamlModelWriter.java
index 974d71685723..bed6ae1182ae 100644
--- 
a/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/YamlModelWriter.java
+++ 
b/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/YamlModelWriter.java
@@ -2534,6 +2534,7 @@ public class YamlModelWriter extends 
YamlModelWriterSupport {
         doWriteAttribute(jo, "fragment", def.getFragment(), null);
         doWriteAttribute(jo, "partClass", def.getPartClass(), null);
         doWriteAttribute(jo, "partNamespace", def.getPartNamespace(), null);
+        doWriteAttribute(jo, "allowPartClassFromHeader", 
def.getAllowPartClassFromHeader(), null);
         doWriteAttribute(jo, "namespacePrefix", def.getNamespacePrefix(), 
null);
         doWriteAttribute(jo, "xmlStreamWriterWrapper", 
def.getXmlStreamWriterWrapper(), null);
         doWriteAttribute(jo, "schemaLocation", def.getSchemaLocation(), null);
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index e345deaa03b0..d552fbdb2309 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -198,6 +198,22 @@ nodes, and XInclude is not processed. Before, the Flowable 
7 deserializer parsed
 An event that relies on an external DTD or an external entity no longer gets 
their content. A channel that sets
 `deserializerDelegateExpression` keeps its own deserializer, which can parse 
such events.
 
+=== camel-jaxb - the part class and namespace headers are used only when 
allowed
+
+The JAXB data format has a new option `allowPartClassFromHeader` (default 
`false`). The `CamelJaxbPartClass` and
+`CamelJaxbPartNamespace` headers are now used only when this option is `true`; 
otherwise they are ignored, and the
+`partClass` and `partNamespace` options of the data format apply. Before, the 
headers were always used, and took
+precedence over these options.
+
+Routes that set these headers to choose the part class or namespace per 
message must enable the option, for example
+`jaxb.setAllowPartClassFromHeader(true)` in Java, 
`allowPartClassFromHeader="true"` on `<jaxb>` in XML, or
+`allowPartClassFromHeader: true` in YAML. With REST binding, set the data 
format property
+`xml.out.allowPartClassFromHeader=true` on the REST configuration for a REST 
service (the response), or
+`xml.in.allowPartClassFromHeader=true` for the `rest` producer (the request). 
The REST binding does not take this
+option from the JAXB data format configured on the CamelContext (such as 
`camel.dataformat.jaxb.*` in Camel Main).
+
+The SOAP data format (camel-soap) is built on the JAXB data format, and always 
ignores these headers.
+
 === camel-jpa - query parameters from CamelJpaParameters header are bound 
literally
 
 In previous versions, string values supplied in the `CamelJpaParameters` 
header map were evaluated as Simple expressions by the JPA producer.
@@ -1738,9 +1754,9 @@ now also apply to the data formats that the Rest DSL 
binding creates for `json`
 to the data formats of the routes. The request and response bodies of a REST 
service can therefore change, for
 instance null fields are left out. The `camel.rest.dataFormatProperties` 
(`json.in.`, `json.out.`, `xml.in.` and
 `xml.out.`) still take precedence. The `objectMapper`, `xmlMapper`, 
`allowUnmarshallType`, `allowJmsType`,
-`unmarshalType`, `useList`, `collectionType` and `partClass` options are not 
taken over: the body type comes from the
-`type` and `outType` of the verb, and the other options can be set with 
`camel.rest.dataFormatProperties` when the
-binding needs them.
+`unmarshalType`, `useList`, `collectionType`, `partClass` and 
`allowPartClassFromHeader` options are not taken over:
+the body type comes from the `type` and `outType` of the verb, and the other 
options can be set with
+`camel.rest.dataFormatProperties` when the binding needs them.
 
 === camel-support - API components use one thread pool per CamelContext
 
diff --git a/docs/user-manual/modules/ROOT/pages/rest-dsl-binding.adoc 
b/docs/user-manual/modules/ROOT/pages/rest-dsl-binding.adoc
index 3bf8d16a2a44..b63679917897 100644
--- a/docs/user-manual/modules/ROOT/pages/rest-dsl-binding.adoc
+++ b/docs/user-manual/modules/ROOT/pages/rest-dsl-binding.adoc
@@ -90,9 +90,9 @@ The `value` in `dataFormatProperty` must be defined as a 
string value, so we use
 
 The binding creates data formats of its own. They start from the options of 
the data format of the same name that is
 configured on the CamelContext, such as with 
`camel.dataformat.jackson.include=NON_NULL` in Camel Main, except the
-`objectMapper`, `xmlMapper`, `allowUnmarshallType`, `allowJmsType`, 
`unmarshalType`, `useList`, `collectionType` and
-`partClass` options: the body type comes from the `type` and `outType` of the 
verb. The `dataFormatProperty` options are
-applied after them, so they take precedence.
+`objectMapper`, `xmlMapper`, `allowUnmarshallType`, `allowJmsType`, 
`unmarshalType`, `useList`, `collectionType`,
+`partClass` and `allowPartClassFromHeader` options: the body type comes from 
the `type` and `outType` of the verb.
+The `dataFormatProperty` options are applied after them, so they take 
precedence.
 
 To use binding you must include the necessary data formats on the
 classpath, such as `camel-jaxb` / `camel-jacksonxml` (or `camel-jackson3xml`) 
and/or `camel-jackson` (or `camel-jackson3`). And then enable
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 b4424d36fc33..a1e00b09c830 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
@@ -7902,6 +7902,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.", displayName = "Access 
External Schema Protocols"),
+                    @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. The package must have an ObjectFactory class or a jaxb.index file that 
lists the classes. To use a class name instead, set contextPathIsClassName to 
true.", 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"),
@@ -7944,6 +7945,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-canonical.json
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-canonical.json
index 7daec03ae368..e5e9afae3156 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-canonical.json
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-canonical.json
@@ -7773,6 +7773,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."
           },
+          "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",
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-model.json
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-model.json
index ea8a0380020d..3a409d7865bb 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-model.json
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-model.json
@@ -12422,6 +12422,17 @@
         "index" : 13,
         "group" : "advanced",
         "label" : "advanced"
+      }, {
+        "name" : "allowPartClassFromHeader",
+        "type" : "boolean",
+        "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.",
+        "title" : "Allow Part Class From Header",
+        "default" : "false",
+        "displayName" : "Allow Part Class From Header",
+        "kind" : "attribute",
+        "index" : 14,
+        "group" : "advanced",
+        "label" : "advanced"
       }, {
         "name" : "namespacePrefix",
         "type" : "string",
@@ -12429,7 +12440,7 @@
         "title" : "Namespace Prefix",
         "displayName" : "Namespace Prefix",
         "kind" : "attribute",
-        "index" : 14,
+        "index" : 15,
         "group" : "advanced",
         "label" : "advanced"
       }, {
@@ -12439,7 +12450,7 @@
         "title" : "Xml Stream Writer Wrapper",
         "displayName" : "Xml Stream Writer Wrapper",
         "kind" : "attribute",
-        "index" : 15,
+        "index" : 16,
         "group" : "advanced",
         "label" : "advanced"
       }, {
@@ -12449,7 +12460,7 @@
         "title" : "Schema Location",
         "displayName" : "Schema Location",
         "kind" : "attribute",
-        "index" : 16,
+        "index" : 17,
         "group" : "common"
       }, {
         "name" : "noNamespaceSchemaLocation",
@@ -12458,7 +12469,7 @@
         "title" : "No Namespace Schema Location",
         "displayName" : "No Namespace Schema Location",
         "kind" : "attribute",
-        "index" : 17,
+        "index" : 18,
         "group" : "advanced",
         "label" : "advanced"
       }, {
@@ -12468,7 +12479,7 @@
         "title" : "Jaxb Provider Properties",
         "displayName" : "Jaxb Provider Properties",
         "kind" : "attribute",
-        "index" : 18,
+        "index" : 19,
         "group" : "advanced",
         "label" : "advanced"
       }, {
@@ -12479,7 +12490,7 @@
         "default" : "true",
         "displayName" : "Content Type Header",
         "kind" : "attribute",
-        "index" : 19,
+        "index" : 20,
         "group" : "common"
       }, {
         "name" : "accessExternalSchemaProtocols",
@@ -12488,7 +12499,7 @@
         "title" : "Access External Schema Protocols",
         "displayName" : "Access External Schema Protocols",
         "kind" : "attribute",
-        "index" : 20,
+        "index" : 21,
         "group" : "security",
         "label" : "security"
       } ]
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 1b5e8dbb4eb3..fc8ccbe838b5 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
@@ -9892,6 +9892,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."
           },
+          "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