You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/08/16 07:27:27 UTC
[camel] branch main updated: CAMEL-6645: camel-mapstruct component
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 5d90313a0b3 CAMEL-6645: camel-mapstruct component
5d90313a0b3 is described below
commit 5d90313a0b3df7115dedfc48b20a6c8747876894
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Aug 16 09:27:02 2022 +0200
CAMEL-6645: camel-mapstruct component
---
bom/camel-bom/pom.xml | 5 +
camel-dependencies/pom.xml | 1 +
catalog/camel-allcomponents/pom.xml | 4 +
.../org/apache/camel/catalog/components.properties | 1 +
.../apache/camel/catalog/components/mapstruct.json | 35 ++++
components/camel-mapstruct/pom.xml | 94 ++++++++++
.../mapstruct/MapstructComponentConfigurer.java | 72 ++++++++
.../mapstruct/MapstructEndpointConfigurer.java | 52 ++++++
.../mapstruct/MapstructEndpointUriFactory.java | 70 ++++++++
.../services/org/apache/camel/component.properties | 7 +
.../services/org/apache/camel/component/mapstruct | 2 +
.../apache/camel/configurer/mapstruct-component | 2 +
.../org/apache/camel/configurer/mapstruct-endpoint | 2 +
.../org/apache/camel/urifactory/mapstruct-endpoint | 2 +
.../camel/component/mapstruct/mapstruct.json | 35 ++++
.../src/main/docs/mapstruct-component.adoc | 76 ++++++++
.../mapstruct/DefaultMapStructFinder.java | 112 ++++++++++++
.../component/mapstruct/MapStructMapperFinder.java | 42 +++++
.../component/mapstruct/MapstructComponent.java | 88 ++++++++++
.../component/mapstruct/MapstructEndpoint.java | 84 +++++++++
.../component/mapstruct/MapstructProducer.java | 38 ++++
.../component/mapstruct/CamelVehicleToCarTest.java | 72 ++++++++
.../mapstruct/ComponentVehicleToCarTest.java | 97 ++++++++++
.../component/mapstruct/VehicleToCarTest.java | 44 +++++
.../camel/component/mapstruct/dto/CarDto.java | 57 ++++++
.../camel/component/mapstruct/dto/VehicleDto.java | 41 +++++
.../component/mapstruct/mapper/CarMapper.java | 31 ++++
.../src/test/resources/log4j2.properties | 28 +++
components/pom.xml | 1 +
.../org/apache/camel/main/components.properties | 1 +
.../modules/ROOT/examples/json/mapstruct.json | 1 +
docs/components/modules/ROOT/nav.adoc | 1 +
.../modules/ROOT/pages/mapstruct-component.adoc | 1 +
.../component/ComponentsBuilderFactory.java | 13 ++
.../dsl/MapstructComponentBuilderFactory.java | 156 +++++++++++++++++
.../src/generated/resources/metadata.json | 22 +++
.../builder/endpoint/EndpointBuilderFactory.java | 1 +
.../camel/builder/endpoint/EndpointBuilders.java | 1 +
.../builder/endpoint/StaticEndpointBuilders.java | 45 +++++
.../dsl/MapstructEndpointBuilderFactory.java | 195 +++++++++++++++++++++
.../camel-component-known-dependencies.properties | 1 +
parent/pom.xml | 6 +
42 files changed, 1639 insertions(+)
diff --git a/bom/camel-bom/pom.xml b/bom/camel-bom/pom.xml
index 2bbb0891d4d..8ddddd276b7 100644
--- a/bom/camel-bom/pom.xml
+++ b/bom/camel-bom/pom.xml
@@ -1424,6 +1424,11 @@
<artifactId>camel-management-api</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-mapstruct</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-master</artifactId>
diff --git a/camel-dependencies/pom.xml b/camel-dependencies/pom.xml
index 9fc50389c24..bb5a8fac3c5 100644
--- a/camel-dependencies/pom.xml
+++ b/camel-dependencies/pom.xml
@@ -380,6 +380,7 @@
<logback-version>1.2.11</logback-version>
<lucene-version>8.11.1</lucene-version>
<lucene-version-range>[8,9)</lucene-version-range>
+ <mapstruct-version>1.5.2.Final</mapstruct-version>
<maven-antrun-plugin-version>1.6</maven-antrun-plugin-version>
<maven-archetype-packaging-version>2.3</maven-archetype-packaging-version>
<maven-archetype-plugin-version>3.2.0</maven-archetype-plugin-version>
diff --git a/catalog/camel-allcomponents/pom.xml b/catalog/camel-allcomponents/pom.xml
index e218086ac22..966be55838b 100644
--- a/catalog/camel-allcomponents/pom.xml
+++ b/catalog/camel-allcomponents/pom.xml
@@ -937,6 +937,10 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-mail</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-mapstruct</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-master</artifactId>
diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components.properties b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components.properties
index 0739b08e352..55be2e5a7e4 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components.properties
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components.properties
@@ -212,6 +212,7 @@ log
lpr
lucene
lumberjack
+mapstruct
master
metrics
micrometer
diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/mapstruct.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/mapstruct.json
new file mode 100644
index 00000000000..d71813f8b60
--- /dev/null
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/mapstruct.json
@@ -0,0 +1,35 @@
+{
+ "component": {
+ "kind": "component",
+ "name": "mapstruct",
+ "title": "MapStruct",
+ "description": "Type Conversion using Mapstruct",
+ "deprecated": false,
+ "firstVersion": "3.19.0",
+ "label": "transformation",
+ "javaType": "org.apache.camel.component.mapstruct.MapstructComponent",
+ "supportLevel": "Preview",
+ "groupId": "org.apache.camel",
+ "artifactId": "camel-mapstruct",
+ "version": "3.19.0-SNAPSHOT",
+ "scheme": "mapstruct",
+ "extendsScheme": "",
+ "syntax": "mapstruct:className",
+ "async": false,
+ "api": false,
+ "consumerOnly": false,
+ "producerOnly": true,
+ "lenientProperties": false
+ },
+ "componentProperties": {
+ "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during star [...]
+ "mapperPackageName": { "kind": "property", "displayName": "Mapper Package Name", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Package name(s) where Camel should discover Mapstruct mapping classes. Multiple package names can be separated by comma." },
+ "autowiredEnabled": { "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which t [...]
+ "mapStructConverter": { "kind": "property", "displayName": "Map Struct Converter", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.mapstruct.MapStructMapperFinder", "deprecated": false, "autowired": true, "secret": false, "description": "To use a custom MapStructConverter such as adapting to a special runtime." }
+ },
+ "properties": {
+ "className": { "kind": "path", "displayName": "Class Name", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The fully qualified class name of the POJO that mapstruct should convert to (target)" },
+ "mandatory": { "kind": "parameter", "displayName": "Mandatory", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether there must exist a mapstruct converter to convert to the POJO." },
+ "lazyStartProducer": { "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may other [...]
+ }
+}
diff --git a/components/camel-mapstruct/pom.xml b/components/camel-mapstruct/pom.xml
new file mode 100644
index 00000000000..076c7735826
--- /dev/null
+++ b/components/camel-mapstruct/pom.xml
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>3.19.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-mapstruct</artifactId>
+ <packaging>jar</packaging>
+ <name>Camel :: Mapstruct</name>
+ <description>Type Conversion using Mapstruct</description>
+
+ <properties>
+ <firstVersion>3.19.0</firstVersion>
+ <label>transformation</label>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-support</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mapstruct</groupId>
+ <artifactId>mapstruct</artifactId>
+ <version>${mapstruct-version}</version>
+ </dependency>
+
+ <!-- testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-junit5</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-mock</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.8.1</version>
+ <configuration>
+ <annotationProcessorPaths>
+ <path>
+ <groupId>org.mapstruct</groupId>
+ <artifactId>mapstruct-processor</artifactId>
+ <version>${mapstruct-version}</version>
+ </path>
+ </annotationProcessorPaths>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/components/camel-mapstruct/src/generated/java/org/apache/camel/component/mapstruct/MapstructComponentConfigurer.java b/components/camel-mapstruct/src/generated/java/org/apache/camel/component/mapstruct/MapstructComponentConfigurer.java
new file mode 100644
index 00000000000..59d9a679720
--- /dev/null
+++ b/components/camel-mapstruct/src/generated/java/org/apache/camel/component/mapstruct/MapstructComponentConfigurer.java
@@ -0,0 +1,72 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.component.mapstruct;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.ExtendedPropertyConfigurerGetter;
+import org.apache.camel.spi.PropertyConfigurerGetter;
+import org.apache.camel.spi.ConfigurerStrategy;
+import org.apache.camel.spi.GeneratedPropertyConfigurer;
+import org.apache.camel.util.CaseInsensitiveMap;
+import org.apache.camel.support.component.PropertyConfigurerSupport;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+public class MapstructComponentConfigurer extends PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter {
+
+ @Override
+ public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) {
+ MapstructComponent target = (MapstructComponent) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "autowiredenabled":
+ case "autowiredEnabled": target.setAutowiredEnabled(property(camelContext, boolean.class, value)); return true;
+ case "lazystartproducer":
+ case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
+ case "mapstructconverter":
+ case "mapStructConverter": target.setMapStructConverter(property(camelContext, org.apache.camel.component.mapstruct.MapStructMapperFinder.class, value)); return true;
+ case "mapperpackagename":
+ case "mapperPackageName": target.setMapperPackageName(property(camelContext, java.lang.String.class, value)); return true;
+ default: return false;
+ }
+ }
+
+ @Override
+ public String[] getAutowiredNames() {
+ return new String[]{"mapStructConverter"};
+ }
+
+ @Override
+ public Class<?> getOptionType(String name, boolean ignoreCase) {
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "autowiredenabled":
+ case "autowiredEnabled": return boolean.class;
+ case "lazystartproducer":
+ case "lazyStartProducer": return boolean.class;
+ case "mapstructconverter":
+ case "mapStructConverter": return org.apache.camel.component.mapstruct.MapStructMapperFinder.class;
+ case "mapperpackagename":
+ case "mapperPackageName": return java.lang.String.class;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
+ MapstructComponent target = (MapstructComponent) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "autowiredenabled":
+ case "autowiredEnabled": return target.isAutowiredEnabled();
+ case "lazystartproducer":
+ case "lazyStartProducer": return target.isLazyStartProducer();
+ case "mapstructconverter":
+ case "mapStructConverter": return target.getMapStructConverter();
+ case "mapperpackagename":
+ case "mapperPackageName": return target.getMapperPackageName();
+ default: return null;
+ }
+ }
+}
+
diff --git a/components/camel-mapstruct/src/generated/java/org/apache/camel/component/mapstruct/MapstructEndpointConfigurer.java b/components/camel-mapstruct/src/generated/java/org/apache/camel/component/mapstruct/MapstructEndpointConfigurer.java
new file mode 100644
index 00000000000..25d87d9aadf
--- /dev/null
+++ b/components/camel-mapstruct/src/generated/java/org/apache/camel/component/mapstruct/MapstructEndpointConfigurer.java
@@ -0,0 +1,52 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.component.mapstruct;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.ExtendedPropertyConfigurerGetter;
+import org.apache.camel.spi.PropertyConfigurerGetter;
+import org.apache.camel.spi.ConfigurerStrategy;
+import org.apache.camel.spi.GeneratedPropertyConfigurer;
+import org.apache.camel.util.CaseInsensitiveMap;
+import org.apache.camel.support.component.PropertyConfigurerSupport;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+public class MapstructEndpointConfigurer extends PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter {
+
+ @Override
+ public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) {
+ MapstructEndpoint target = (MapstructEndpoint) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "lazystartproducer":
+ case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
+ case "mandatory": target.setMandatory(property(camelContext, boolean.class, value)); return true;
+ default: return false;
+ }
+ }
+
+ @Override
+ public Class<?> getOptionType(String name, boolean ignoreCase) {
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "lazystartproducer":
+ case "lazyStartProducer": return boolean.class;
+ case "mandatory": return boolean.class;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
+ MapstructEndpoint target = (MapstructEndpoint) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "lazystartproducer":
+ case "lazyStartProducer": return target.isLazyStartProducer();
+ case "mandatory": return target.isMandatory();
+ default: return null;
+ }
+ }
+}
+
diff --git a/components/camel-mapstruct/src/generated/java/org/apache/camel/component/mapstruct/MapstructEndpointUriFactory.java b/components/camel-mapstruct/src/generated/java/org/apache/camel/component/mapstruct/MapstructEndpointUriFactory.java
new file mode 100644
index 00000000000..1a6d03fad7d
--- /dev/null
+++ b/components/camel-mapstruct/src/generated/java/org/apache/camel/component/mapstruct/MapstructEndpointUriFactory.java
@@ -0,0 +1,70 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.component.mapstruct;
+
+import java.net.URISyntaxException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.camel.spi.EndpointUriFactory;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+public class MapstructEndpointUriFactory extends org.apache.camel.support.component.EndpointUriFactorySupport implements EndpointUriFactory {
+
+ private static final String BASE = ":className";
+
+ private static final Set<String> PROPERTY_NAMES;
+ private static final Set<String> SECRET_PROPERTY_NAMES;
+ private static final Set<String> MULTI_VALUE_PREFIXES;
+ static {
+ Set<String> props = new HashSet<>(3);
+ props.add("className");
+ props.add("lazyStartProducer");
+ props.add("mandatory");
+ PROPERTY_NAMES = Collections.unmodifiableSet(props);
+ SECRET_PROPERTY_NAMES = Collections.emptySet();
+ MULTI_VALUE_PREFIXES = Collections.emptySet();
+ }
+
+ @Override
+ public boolean isEnabled(String scheme) {
+ return "mapstruct".equals(scheme);
+ }
+
+ @Override
+ public String buildUri(String scheme, Map<String, Object> properties, boolean encode) throws URISyntaxException {
+ String syntax = scheme + BASE;
+ String uri = syntax;
+
+ Map<String, Object> copy = new HashMap<>(properties);
+
+ uri = buildPathParameter(syntax, uri, "className", null, true, copy);
+ uri = buildQueryParameters(uri, copy, encode);
+ return uri;
+ }
+
+ @Override
+ public Set<String> propertyNames() {
+ return PROPERTY_NAMES;
+ }
+
+ @Override
+ public Set<String> secretPropertyNames() {
+ return SECRET_PROPERTY_NAMES;
+ }
+
+ @Override
+ public Set<String> multiValuePrefixes() {
+ return MULTI_VALUE_PREFIXES;
+ }
+
+ @Override
+ public boolean isLenientProperties() {
+ return false;
+ }
+}
+
diff --git a/components/camel-mapstruct/src/generated/resources/META-INF/services/org/apache/camel/component.properties b/components/camel-mapstruct/src/generated/resources/META-INF/services/org/apache/camel/component.properties
new file mode 100644
index 00000000000..2ca0368bc13
--- /dev/null
+++ b/components/camel-mapstruct/src/generated/resources/META-INF/services/org/apache/camel/component.properties
@@ -0,0 +1,7 @@
+# Generated by camel build tools - do NOT edit this file!
+components=mapstruct
+groupId=org.apache.camel
+artifactId=camel-mapstruct
+version=3.19.0-SNAPSHOT
+projectName=Camel :: Mapstruct
+projectDescription=Type Conversion using Mapstruct
diff --git a/components/camel-mapstruct/src/generated/resources/META-INF/services/org/apache/camel/component/mapstruct b/components/camel-mapstruct/src/generated/resources/META-INF/services/org/apache/camel/component/mapstruct
new file mode 100644
index 00000000000..cb4f9c67bae
--- /dev/null
+++ b/components/camel-mapstruct/src/generated/resources/META-INF/services/org/apache/camel/component/mapstruct
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.mapstruct.MapstructComponent
diff --git a/components/camel-mapstruct/src/generated/resources/META-INF/services/org/apache/camel/configurer/mapstruct-component b/components/camel-mapstruct/src/generated/resources/META-INF/services/org/apache/camel/configurer/mapstruct-component
new file mode 100644
index 00000000000..e16640a5eb7
--- /dev/null
+++ b/components/camel-mapstruct/src/generated/resources/META-INF/services/org/apache/camel/configurer/mapstruct-component
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.mapstruct.MapstructComponentConfigurer
diff --git a/components/camel-mapstruct/src/generated/resources/META-INF/services/org/apache/camel/configurer/mapstruct-endpoint b/components/camel-mapstruct/src/generated/resources/META-INF/services/org/apache/camel/configurer/mapstruct-endpoint
new file mode 100644
index 00000000000..349ab011e08
--- /dev/null
+++ b/components/camel-mapstruct/src/generated/resources/META-INF/services/org/apache/camel/configurer/mapstruct-endpoint
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.mapstruct.MapstructEndpointConfigurer
diff --git a/components/camel-mapstruct/src/generated/resources/META-INF/services/org/apache/camel/urifactory/mapstruct-endpoint b/components/camel-mapstruct/src/generated/resources/META-INF/services/org/apache/camel/urifactory/mapstruct-endpoint
new file mode 100644
index 00000000000..cbdfb37b9b0
--- /dev/null
+++ b/components/camel-mapstruct/src/generated/resources/META-INF/services/org/apache/camel/urifactory/mapstruct-endpoint
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.mapstruct.MapstructEndpointUriFactory
diff --git a/components/camel-mapstruct/src/generated/resources/org/apache/camel/component/mapstruct/mapstruct.json b/components/camel-mapstruct/src/generated/resources/org/apache/camel/component/mapstruct/mapstruct.json
new file mode 100644
index 00000000000..d71813f8b60
--- /dev/null
+++ b/components/camel-mapstruct/src/generated/resources/org/apache/camel/component/mapstruct/mapstruct.json
@@ -0,0 +1,35 @@
+{
+ "component": {
+ "kind": "component",
+ "name": "mapstruct",
+ "title": "MapStruct",
+ "description": "Type Conversion using Mapstruct",
+ "deprecated": false,
+ "firstVersion": "3.19.0",
+ "label": "transformation",
+ "javaType": "org.apache.camel.component.mapstruct.MapstructComponent",
+ "supportLevel": "Preview",
+ "groupId": "org.apache.camel",
+ "artifactId": "camel-mapstruct",
+ "version": "3.19.0-SNAPSHOT",
+ "scheme": "mapstruct",
+ "extendsScheme": "",
+ "syntax": "mapstruct:className",
+ "async": false,
+ "api": false,
+ "consumerOnly": false,
+ "producerOnly": true,
+ "lenientProperties": false
+ },
+ "componentProperties": {
+ "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during star [...]
+ "mapperPackageName": { "kind": "property", "displayName": "Mapper Package Name", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Package name(s) where Camel should discover Mapstruct mapping classes. Multiple package names can be separated by comma." },
+ "autowiredEnabled": { "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which t [...]
+ "mapStructConverter": { "kind": "property", "displayName": "Map Struct Converter", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.mapstruct.MapStructMapperFinder", "deprecated": false, "autowired": true, "secret": false, "description": "To use a custom MapStructConverter such as adapting to a special runtime." }
+ },
+ "properties": {
+ "className": { "kind": "path", "displayName": "Class Name", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The fully qualified class name of the POJO that mapstruct should convert to (target)" },
+ "mandatory": { "kind": "parameter", "displayName": "Mandatory", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether there must exist a mapstruct converter to convert to the POJO." },
+ "lazyStartProducer": { "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may other [...]
+ }
+}
diff --git a/components/camel-mapstruct/src/main/docs/mapstruct-component.adoc b/components/camel-mapstruct/src/main/docs/mapstruct-component.adoc
new file mode 100644
index 00000000000..665ad0ef7f7
--- /dev/null
+++ b/components/camel-mapstruct/src/main/docs/mapstruct-component.adoc
@@ -0,0 +1,76 @@
+= MapStruct Component
+:doctitle: MapStruct
+:shortname: mapstruct
+:artifactid: camel-mapstruct
+:description: Type Conversion using Mapstruct
+:since: 3.19
+:supportlevel: Preview
+:component-header: Only producer is supported
+//Manually maintained attributes
+:camel-spring-boot-name: mapstruct
+
+*Since Camel {since}*
+
+*{component-header}*
+
+The camel-mapstruct component is used for converting POJOs using https://mapstruct.org/[MapStruct].
+
+== URI format
+
+----
+mapstruct:className[?options]
+----
+
+Where `className` is the fully qualified class name of the POJO to convert to.
+
+// component-configure options: START
+
+// component-configure options: END
+
+// component options: START
+include::partial$component-configure-options.adoc[]
+include::partial$component-endpoint-options.adoc[]
+// component options: END
+
+// endpoint options: START
+
+// endpoint options: END
+// component headers: START
+include::partial$component-endpoint-headers.adoc[]
+// component headers: END
+
+== Setting up MapStruct
+
+The camel-mapstruct component must be configured with one or more package names, for classpath scanning MapStruct _Mapper_ classes.
+This is needed because the _Mapper_ classes are to be used for converting POJOs with MapStruct.
+
+For example to set up two packages you can do as following:
+
+[source,java]
+----
+MapstructComponent mc = context.getComponent("mapstruct", MapstructComponent.class);
+mc.setMapperPackageName("com.foo.mapper,com.bar.mapper");
+----
+
+This can also be configured in `application.properties`:
+
+[source,properties]
+----
+camel.component.mapstruct.mapper-package-name = com.foo.mapper,com.bar.mapper
+----
+
+Camel will on startup scan these packages for classes which names ends with _Mapper_. These classes
+are then introspected to discover the mapping methods. These mapping methods are then registered
+into the Camel xref:manual::type-converter.adoc[Type Converter] registry. This means that you can
+also use type converter to convert the POJOs with MapStruct, such as:
+
+[source,java]
+----
+from("direct:foo")
+ .convertBodyTo(MyFooDto.class);
+----
+
+Where `MyFooDto` is a POJO that MapStruct is able to convert to/from.
+
+
+include::spring-boot:partial$starter.adoc[]
diff --git a/components/camel-mapstruct/src/main/java/org/apache/camel/component/mapstruct/DefaultMapStructFinder.java b/components/camel-mapstruct/src/main/java/org/apache/camel/component/mapstruct/DefaultMapStructFinder.java
new file mode 100644
index 00000000000..7e1f93bcde6
--- /dev/null
+++ b/components/camel-mapstruct/src/main/java/org/apache/camel/component/mapstruct/DefaultMapStructFinder.java
@@ -0,0 +1,112 @@
+/*
+ * 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.component.mapstruct;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.support.ObjectHelper;
+import org.apache.camel.support.SimpleTypeConverter;
+import org.apache.camel.support.service.ServiceSupport;
+import org.apache.camel.util.ReflectionHelper;
+import org.mapstruct.factory.Mappers;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DefaultMapStructFinder extends ServiceSupport implements MapStructMapperFinder, CamelContextAware {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DefaultMapStructFinder.class);
+
+ private CamelContext camelContext;
+ private String mapperPackageName;
+
+ @Override
+ public CamelContext getCamelContext() {
+ return camelContext;
+ }
+
+ @Override
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+ public String getMapperPackageName() {
+ return mapperPackageName;
+ }
+
+ @Override
+ public int discoverMappings(Class<?> clazz) {
+ final AtomicInteger answer = new AtomicInteger();
+ try {
+ // is there a generated mapper
+ final Object mapper = Mappers.getMapper(clazz);
+ if (mapper != null) {
+ ReflectionHelper.doWithMethods(clazz, mc -> {
+ // must not be a default method
+ if (mc.isDefault()) {
+ return;
+ }
+ // must have a single parameter
+ int parameterCount = mc.getParameterCount();
+ if (parameterCount != 1) {
+ return;
+ }
+ Class<?> from = mc.getParameterTypes()[0];
+ // must return a value
+ Class<?> to = mc.getReturnType();
+ if (to.equals(Void.class)) {
+ return;
+ }
+ // okay register this method as a Camel type converter
+ camelContext.getTypeConverterRegistry()
+ .addTypeConverter(to, from, new SimpleTypeConverter(
+ false, (type, exchange, value) -> ObjectHelper.invokeMethod(mc, mapper, value)));
+ LOG.debug("Added MapStruct type converter: {} -> {}", from, to);
+ answer.incrementAndGet();
+ });
+ }
+ } catch (Throwable e) {
+ LOG.debug("Mapper class: {} is not a MapStruct Mapper. Skipping this class.", clazz);
+ }
+
+ return answer.get();
+ }
+
+ public void setMapperPackageName(String mapperPackageName) {
+ this.mapperPackageName = mapperPackageName;
+ }
+
+ @Override
+ protected void doInit() throws Exception {
+ if (mapperPackageName != null) {
+ String[] names = mapperPackageName.split(",");
+ ExtendedCamelContext ecc = camelContext.adapt(ExtendedCamelContext.class);
+ var set = ecc.getPackageScanClassResolver()
+ .findByFilter(f -> f.getName().endsWith("Mapper"), names);
+ if (!set.isEmpty()) {
+ int converters = 0;
+ for (Class<?> clazz : set) {
+ converters += discoverMappings(clazz);
+ }
+ LOG.info("Discovered {} MapStruct type converters from classpath scanning: {}", converters, mapperPackageName);
+ }
+ }
+ }
+
+}
diff --git a/components/camel-mapstruct/src/main/java/org/apache/camel/component/mapstruct/MapStructMapperFinder.java b/components/camel-mapstruct/src/main/java/org/apache/camel/component/mapstruct/MapStructMapperFinder.java
new file mode 100644
index 00000000000..1bfcc972bdf
--- /dev/null
+++ b/components/camel-mapstruct/src/main/java/org/apache/camel/component/mapstruct/MapStructMapperFinder.java
@@ -0,0 +1,42 @@
+/*
+ * 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.component.mapstruct;
+
+import org.apache.camel.StaticService;
+
+public interface MapStructMapperFinder extends StaticService {
+
+ /**
+ * Package name(s) where Camel should discover Mapstruct mapping classes. Multiple package names can be separated by
+ * comma.
+ */
+ void setMapperPackageName(String mapperPackageName);
+
+ /**
+ * Package name(s) where Camel should discover Mapstruct mapping classes. Multiple package names can be separated by
+ * comma.
+ */
+ String getMapperPackageName();
+
+ /**
+ * Callback on a found mapper class
+ *
+ * @return number of mapping methods loaded from the given mapper class
+ */
+ int discoverMappings(Class<?> clazz);
+
+}
diff --git a/components/camel-mapstruct/src/main/java/org/apache/camel/component/mapstruct/MapstructComponent.java b/components/camel-mapstruct/src/main/java/org/apache/camel/component/mapstruct/MapstructComponent.java
new file mode 100644
index 00000000000..ee71a25e3a6
--- /dev/null
+++ b/components/camel-mapstruct/src/main/java/org/apache/camel/component/mapstruct/MapstructComponent.java
@@ -0,0 +1,88 @@
+/*
+ * 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.component.mapstruct;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.Endpoint;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.support.DefaultComponent;
+import org.apache.camel.support.service.ServiceHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@org.apache.camel.spi.annotations.Component("mapstruct")
+public class MapstructComponent extends DefaultComponent {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MapstructComponent.class);
+
+ @Metadata(label = "advanced", autowired = true)
+ private MapStructMapperFinder mapStructConverter;
+ @Metadata(required = true)
+ private String mapperPackageName;
+
+ @Override
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ MapstructEndpoint answer = new MapstructEndpoint(uri, this);
+ answer.setClassName(remaining);
+ setProperties(answer, parameters);
+ return answer;
+ }
+
+ public MapStructMapperFinder getMapStructConverter() {
+ return mapStructConverter;
+ }
+
+ /**
+ * To use a custom MapStructConverter such as adapting to a special runtime.
+ */
+ public void setMapStructConverter(MapStructMapperFinder mapStructConverter) {
+ this.mapStructConverter = mapStructConverter;
+ }
+
+ public String getMapperPackageName() {
+ return mapperPackageName;
+ }
+
+ /**
+ * Package name(s) where Camel should discover Mapstruct mapping classes. Multiple package names can be separated by
+ * comma.
+ */
+ public void setMapperPackageName(String mapperPackageName) {
+ this.mapperPackageName = mapperPackageName;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ if (mapStructConverter == null) {
+ mapStructConverter = new DefaultMapStructFinder();
+ CamelContextAware.trySetCamelContext(mapStructConverter, getCamelContext());
+ mapStructConverter.setMapperPackageName(mapperPackageName);
+ }
+ ServiceHelper.startService(mapStructConverter);
+
+ if (mapStructConverter.getMapperPackageName() == null) {
+ LOG.warn("Cannot find MapStruct Mapper classes because mapperPackageName has not been configured");
+ }
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ ServiceHelper.stopService(mapStructConverter);
+ }
+}
diff --git a/components/camel-mapstruct/src/main/java/org/apache/camel/component/mapstruct/MapstructEndpoint.java b/components/camel-mapstruct/src/main/java/org/apache/camel/component/mapstruct/MapstructEndpoint.java
new file mode 100644
index 00000000000..51866593ef4
--- /dev/null
+++ b/components/camel-mapstruct/src/main/java/org/apache/camel/component/mapstruct/MapstructEndpoint.java
@@ -0,0 +1,84 @@
+/*
+ * 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.component.mapstruct;
+
+import org.apache.camel.Category;
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriPath;
+import org.apache.camel.support.DefaultEndpoint;
+import org.apache.camel.util.ObjectHelper;
+
+@UriEndpoint(firstVersion = "3.19.0", scheme = "mapstruct", title = "MapStruct", syntax = "mapstruct:className",
+ producerOnly = true,
+ category = { Category.TRANSFORMATION })
+public class MapstructEndpoint extends DefaultEndpoint {
+
+ @UriPath
+ @Metadata(required = true)
+ private String className;
+ private transient Class<?> clazz;
+ @UriParam(defaultValue = "true")
+ private boolean mandatory = true;
+
+ public MapstructEndpoint(String endpointUri, Component component) {
+ super(endpointUri, component);
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ return new MapstructProducer(this, clazz, mandatory);
+ }
+
+ @Override
+ public Consumer createConsumer(Processor processor) throws Exception {
+ throw new UnsupportedOperationException("Consumer is not supported");
+ }
+
+ public String getClassName() {
+ return className;
+ }
+
+ /**
+ * The fully qualified class name of the POJO that mapstruct should convert to (target)
+ */
+ public void setClassName(String className) {
+ this.className = className;
+ }
+
+ public boolean isMandatory() {
+ return mandatory;
+ }
+
+ /**
+ * Whether there must exist a mapstruct converter to convert to the POJO.
+ */
+ public void setMandatory(boolean mandatory) {
+ this.mandatory = mandatory;
+ }
+
+ @Override
+ protected void doBuild() throws Exception {
+ ObjectHelper.notNull(className, "className");
+ clazz = getCamelContext().getClassResolver().resolveMandatoryClass(className);
+ }
+}
diff --git a/components/camel-mapstruct/src/main/java/org/apache/camel/component/mapstruct/MapstructProducer.java b/components/camel-mapstruct/src/main/java/org/apache/camel/component/mapstruct/MapstructProducer.java
new file mode 100644
index 00000000000..37cf9d4504c
--- /dev/null
+++ b/components/camel-mapstruct/src/main/java/org/apache/camel/component/mapstruct/MapstructProducer.java
@@ -0,0 +1,38 @@
+/*
+ * 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.component.mapstruct;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.support.processor.ConvertBodyProcessor;
+
+public class MapstructProducer extends DefaultProducer {
+
+ private final Processor converter;
+
+ public MapstructProducer(MapstructEndpoint endpoint, Class<?> clazz, boolean mandatory) {
+ super(endpoint);
+ // we use convert body that will use type converter to find the mapstruct mapper
+ this.converter = new ConvertBodyProcessor(clazz, null, mandatory);
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ converter.process(exchange);
+ }
+}
diff --git a/components/camel-mapstruct/src/test/java/org/apache/camel/component/mapstruct/CamelVehicleToCarTest.java b/components/camel-mapstruct/src/test/java/org/apache/camel/component/mapstruct/CamelVehicleToCarTest.java
new file mode 100644
index 00000000000..fcd702564a7
--- /dev/null
+++ b/components/camel-mapstruct/src/test/java/org/apache/camel/component/mapstruct/CamelVehicleToCarTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.component.mapstruct;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mapstruct.dto.CarDto;
+import org.apache.camel.component.mapstruct.dto.VehicleDto;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class CamelVehicleToCarTest extends CamelTestSupport {
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ MapStructMapperFinder converter = new DefaultMapStructFinder();
+ converter.setMapperPackageName("org.apache.camel.component.mapstruct.mapper");
+
+ CamelContext context = super.createCamelContext();
+ context.addService(converter);
+ return context;
+ }
+
+ @Test
+ public void testConverter() throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ VehicleDto v = new VehicleDto();
+ v.setCompany("Volvo");
+ v.setName("XC40");
+ v.setYear(2021);
+ v.setPower("true");
+
+ CarDto car = template.requestBody("direct:start", v, CarDto.class);
+ Assertions.assertNotNull(car);
+
+ Assertions.assertEquals("Volvo", car.getBrand());
+ Assertions.assertEquals("XC40", car.getModel());
+ Assertions.assertEquals(2021, car.getYear());
+ Assertions.assertEquals(true, car.isElectric());
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .convertBodyTo(CarDto.class)
+ .to("mock:result");
+ }
+ };
+ }
+}
diff --git a/components/camel-mapstruct/src/test/java/org/apache/camel/component/mapstruct/ComponentVehicleToCarTest.java b/components/camel-mapstruct/src/test/java/org/apache/camel/component/mapstruct/ComponentVehicleToCarTest.java
new file mode 100644
index 00000000000..e3a88a87873
--- /dev/null
+++ b/components/camel-mapstruct/src/test/java/org/apache/camel/component/mapstruct/ComponentVehicleToCarTest.java
@@ -0,0 +1,97 @@
+/*
+ * 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.component.mapstruct;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mapstruct.dto.CarDto;
+import org.apache.camel.component.mapstruct.dto.VehicleDto;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class ComponentVehicleToCarTest extends CamelTestSupport {
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+
+ MapstructComponent mc = context.getComponent("mapstruct", MapstructComponent.class);
+ mc.setMapperPackageName("org.apache.camel.component.mapstruct.mapper");
+
+ return context;
+ }
+
+ @Test
+ public void testComponent() throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ VehicleDto v = new VehicleDto();
+ v.setCompany("Volvo");
+ v.setName("XC40");
+ v.setYear(2021);
+ v.setPower("true");
+
+ CarDto car = template.requestBody("direct:component", v, CarDto.class);
+ Assertions.assertNotNull(car);
+
+ Assertions.assertEquals("Volvo", car.getBrand());
+ Assertions.assertEquals("XC40", car.getModel());
+ Assertions.assertEquals(2021, car.getYear());
+ Assertions.assertEquals(true, car.isElectric());
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testConverter() throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ VehicleDto v = new VehicleDto();
+ v.setCompany("Volvo");
+ v.setName("XC60");
+ v.setYear(2018);
+ v.setPower("false");
+
+ CarDto car = template.requestBody("direct:convert", v, CarDto.class);
+ Assertions.assertNotNull(car);
+
+ Assertions.assertEquals("Volvo", car.getBrand());
+ Assertions.assertEquals("XC60", car.getModel());
+ Assertions.assertEquals(2018, car.getYear());
+ Assertions.assertEquals(false, car.isElectric());
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:component")
+ .to("mapstruct:" + CarDto.class.getName())
+ .to("mock:result");
+
+ from("direct:convert")
+ .convertBodyTo(CarDto.class)
+ .to("mock:result");
+ }
+ };
+ }
+}
diff --git a/components/camel-mapstruct/src/test/java/org/apache/camel/component/mapstruct/VehicleToCarTest.java b/components/camel-mapstruct/src/test/java/org/apache/camel/component/mapstruct/VehicleToCarTest.java
new file mode 100644
index 00000000000..6d9ef41c16a
--- /dev/null
+++ b/components/camel-mapstruct/src/test/java/org/apache/camel/component/mapstruct/VehicleToCarTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.component.mapstruct;
+
+import org.apache.camel.component.mapstruct.dto.CarDto;
+import org.apache.camel.component.mapstruct.dto.VehicleDto;
+import org.apache.camel.component.mapstruct.mapper.CarMapper;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mapstruct.factory.Mappers;
+
+public class VehicleToCarTest {
+
+ @Test
+ public void testMapstruct() throws Exception {
+ CarMapper mapper = Mappers.getMapper(CarMapper.class);
+
+ VehicleDto v = new VehicleDto();
+ v.setCompany("Volvo");
+ v.setName("XC40");
+ v.setYear(2021);
+ v.setPower("true");
+ CarDto car = mapper.toCar(v);
+
+ Assertions.assertEquals("Volvo", car.getBrand());
+ Assertions.assertEquals("XC40", car.getModel());
+ Assertions.assertEquals(2021, car.getYear());
+ Assertions.assertEquals(true, car.isElectric());
+ }
+}
diff --git a/components/camel-mapstruct/src/test/java/org/apache/camel/component/mapstruct/dto/CarDto.java b/components/camel-mapstruct/src/test/java/org/apache/camel/component/mapstruct/dto/CarDto.java
new file mode 100644
index 00000000000..f0a0a35ef7e
--- /dev/null
+++ b/components/camel-mapstruct/src/test/java/org/apache/camel/component/mapstruct/dto/CarDto.java
@@ -0,0 +1,57 @@
+/*
+ * 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.component.mapstruct.dto;
+
+public class CarDto {
+
+ private String brand;
+ private String model;
+ private int year;
+ private boolean electric;
+
+ public String getBrand() {
+ return brand;
+ }
+
+ public void setBrand(String brand) {
+ this.brand = brand;
+ }
+
+ public String getModel() {
+ return model;
+ }
+
+ public void setModel(String model) {
+ this.model = model;
+ }
+
+ public int getYear() {
+ return year;
+ }
+
+ public void setYear(int year) {
+ this.year = year;
+ }
+
+ public boolean isElectric() {
+ return electric;
+ }
+
+ public void setElectric(boolean electric) {
+ this.electric = electric;
+ }
+}
diff --git a/components/camel-mapstruct/src/test/java/org/apache/camel/component/mapstruct/dto/VehicleDto.java b/components/camel-mapstruct/src/test/java/org/apache/camel/component/mapstruct/dto/VehicleDto.java
new file mode 100644
index 00000000000..bf18685dfc8
--- /dev/null
+++ b/components/camel-mapstruct/src/test/java/org/apache/camel/component/mapstruct/dto/VehicleDto.java
@@ -0,0 +1,41 @@
+package org.apache.camel.component.mapstruct.dto;
+
+public class VehicleDto {
+
+ private String company;
+ private String name;
+ private String power;
+ private int year;
+
+ public String getCompany() {
+ return company;
+ }
+
+ public void setCompany(String company) {
+ this.company = company;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getPower() {
+ return power;
+ }
+
+ public void setPower(String power) {
+ this.power = power;
+ }
+
+ public int getYear() {
+ return year;
+ }
+
+ public void setYear(int year) {
+ this.year = year;
+ }
+}
diff --git a/components/camel-mapstruct/src/test/java/org/apache/camel/component/mapstruct/mapper/CarMapper.java b/components/camel-mapstruct/src/test/java/org/apache/camel/component/mapstruct/mapper/CarMapper.java
new file mode 100644
index 00000000000..43801a3fe75
--- /dev/null
+++ b/components/camel-mapstruct/src/test/java/org/apache/camel/component/mapstruct/mapper/CarMapper.java
@@ -0,0 +1,31 @@
+/*
+ * 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.component.mapstruct.mapper;
+
+import org.apache.camel.component.mapstruct.dto.CarDto;
+import org.apache.camel.component.mapstruct.dto.VehicleDto;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+
+@Mapper
+public interface CarMapper {
+
+ @Mapping(source = "company", target = "brand")
+ @Mapping(source = "name", target = "model")
+ @Mapping(source = "power", target = "electric")
+ CarDto toCar(VehicleDto vehicle);
+}
diff --git a/components/camel-mapstruct/src/test/resources/log4j2.properties b/components/camel-mapstruct/src/test/resources/log4j2.properties
new file mode 100644
index 00000000000..e9bce2146b1
--- /dev/null
+++ b/components/camel-mapstruct/src/test/resources/log4j2.properties
@@ -0,0 +1,28 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+appender.file.type = File
+appender.file.name = file
+appender.file.fileName = target/camel-mapstruct-test.log
+appender.file.layout.type = PatternLayout
+appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+appender.stdout.type = Console
+appender.stdout.name = stdout
+appender.stdout.layout.type = PatternLayout
+appender.stdout.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+rootLogger.level = INFO
+rootLogger.appenderRef.file.ref = file
diff --git a/components/pom.xml b/components/pom.xml
index f32114d1639..5bc2edf5256 100644
--- a/components/pom.xml
+++ b/components/pom.xml
@@ -220,6 +220,7 @@
<module>camel-lumberjack</module>
<module>camel-lzf</module>
<module>camel-mail</module>
+ <module>camel-mapstruct</module>
<module>camel-metrics</module>
<module>camel-micrometer</module>
<module>camel-microprofile</module>
diff --git a/core/camel-main/src/generated/resources/org/apache/camel/main/components.properties b/core/camel-main/src/generated/resources/org/apache/camel/main/components.properties
index 0739b08e352..55be2e5a7e4 100644
--- a/core/camel-main/src/generated/resources/org/apache/camel/main/components.properties
+++ b/core/camel-main/src/generated/resources/org/apache/camel/main/components.properties
@@ -212,6 +212,7 @@ log
lpr
lucene
lumberjack
+mapstruct
master
metrics
micrometer
diff --git a/docs/components/modules/ROOT/examples/json/mapstruct.json b/docs/components/modules/ROOT/examples/json/mapstruct.json
new file mode 120000
index 00000000000..c099b084088
--- /dev/null
+++ b/docs/components/modules/ROOT/examples/json/mapstruct.json
@@ -0,0 +1 @@
+../../../../../../components/camel-mapstruct/src/generated/resources/org/apache/camel/component/mapstruct/mapstruct.json
\ No newline at end of file
diff --git a/docs/components/modules/ROOT/nav.adoc b/docs/components/modules/ROOT/nav.adoc
index ed85118544b..5a568584049 100644
--- a/docs/components/modules/ROOT/nav.adoc
+++ b/docs/components/modules/ROOT/nav.adoc
@@ -221,6 +221,7 @@
** xref:lucene-component.adoc[Lucene]
** xref:lumberjack-component.adoc[Lumberjack]
** xref:mail-component.adoc[Mail]
+** xref:mapstruct-component.adoc[MapStruct]
** xref:master-component.adoc[Master]
** xref:metrics-component.adoc[Metrics]
** xref:micrometer-component.adoc[Micrometer]
diff --git a/docs/components/modules/ROOT/pages/mapstruct-component.adoc b/docs/components/modules/ROOT/pages/mapstruct-component.adoc
new file mode 120000
index 00000000000..b0437605bcb
--- /dev/null
+++ b/docs/components/modules/ROOT/pages/mapstruct-component.adoc
@@ -0,0 +1 @@
+../../../../../components/camel-mapstruct/src/main/docs/mapstruct-component.adoc
\ No newline at end of file
diff --git a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/ComponentsBuilderFactory.java b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/ComponentsBuilderFactory.java
index 19e55a688bd..1f5340f6812 100644
--- a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/ComponentsBuilderFactory.java
+++ b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/ComponentsBuilderFactory.java
@@ -2890,6 +2890,19 @@ public interface ComponentsBuilderFactory {
static org.apache.camel.builder.component.dsl.LumberjackComponentBuilderFactory.LumberjackComponentBuilder lumberjack() {
return org.apache.camel.builder.component.dsl.LumberjackComponentBuilderFactory.lumberjack();
}
+ /**
+ * MapStruct (camel-mapstruct)
+ * Type Conversion using Mapstruct
+ *
+ * Category: transformation
+ * Since: 3.19
+ * Maven coordinates: org.apache.camel:camel-mapstruct
+ *
+ * @return the dsl builder
+ */
+ static org.apache.camel.builder.component.dsl.MapstructComponentBuilderFactory.MapstructComponentBuilder mapstruct() {
+ return org.apache.camel.builder.component.dsl.MapstructComponentBuilderFactory.mapstruct();
+ }
/**
* Master (camel-master)
* Have only a single consumer in a cluster consuming from a given endpoint;
diff --git a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/MapstructComponentBuilderFactory.java b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/MapstructComponentBuilderFactory.java
new file mode 100644
index 00000000000..610cda4e42e
--- /dev/null
+++ b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/MapstructComponentBuilderFactory.java
@@ -0,0 +1,156 @@
+/*
+ * 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.builder.component.dsl;
+
+import javax.annotation.Generated;
+import org.apache.camel.Component;
+import org.apache.camel.builder.component.AbstractComponentBuilder;
+import org.apache.camel.builder.component.ComponentBuilder;
+import org.apache.camel.component.mapstruct.MapstructComponent;
+
+/**
+ * Type Conversion using Mapstruct
+ *
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.ComponentDslMojo")
+public interface MapstructComponentBuilderFactory {
+
+ /**
+ * MapStruct (camel-mapstruct)
+ * Type Conversion using Mapstruct
+ *
+ * Category: transformation
+ * Since: 3.19
+ * Maven coordinates: org.apache.camel:camel-mapstruct
+ *
+ * @return the dsl builder
+ */
+ static MapstructComponentBuilder mapstruct() {
+ return new MapstructComponentBuilderImpl();
+ }
+
+ /**
+ * Builder for the MapStruct component.
+ */
+ interface MapstructComponentBuilder
+ extends
+ ComponentBuilder<MapstructComponent> {
+ /**
+ * Whether the producer should be started lazy (on the first message).
+ * By starting lazy you can use this to allow CamelContext and routes to
+ * startup in situations where a producer may otherwise fail during
+ * starting and cause the route to fail being started. By deferring this
+ * startup to be lazy then the startup failure can be handled during
+ * routing messages via Camel's routing error handlers. Beware that when
+ * the first message is processed then creating and starting the
+ * producer may take a little time and prolong the total processing time
+ * of the processing.
+ *
+ * The option is a: <code>boolean</code> type.
+ *
+ * Default: false
+ * Group: producer
+ *
+ * @param lazyStartProducer the value to set
+ * @return the dsl builder
+ */
+ default MapstructComponentBuilder lazyStartProducer(
+ boolean lazyStartProducer) {
+ doSetProperty("lazyStartProducer", lazyStartProducer);
+ return this;
+ }
+ /**
+ * Package name(s) where Camel should discover Mapstruct mapping
+ * classes. Multiple package names can be separated by comma.
+ *
+ * The option is a: <code>java.lang.String</code> type.
+ *
+ * Group: producer
+ *
+ * @param mapperPackageName the value to set
+ * @return the dsl builder
+ */
+ default MapstructComponentBuilder mapperPackageName(
+ java.lang.String mapperPackageName) {
+ doSetProperty("mapperPackageName", mapperPackageName);
+ return this;
+ }
+ /**
+ * Whether autowiring is enabled. This is used for automatic autowiring
+ * options (the option must be marked as autowired) by looking up in the
+ * registry to find if there is a single instance of matching type,
+ * which then gets configured on the component. This can be used for
+ * automatic configuring JDBC data sources, JMS connection factories,
+ * AWS Clients, etc.
+ *
+ * The option is a: <code>boolean</code> type.
+ *
+ * Default: true
+ * Group: advanced
+ *
+ * @param autowiredEnabled the value to set
+ * @return the dsl builder
+ */
+ default MapstructComponentBuilder autowiredEnabled(
+ boolean autowiredEnabled) {
+ doSetProperty("autowiredEnabled", autowiredEnabled);
+ return this;
+ }
+ /**
+ * To use a custom MapStructConverter such as adapting to a special
+ * runtime.
+ *
+ * The option is a:
+ * <code>org.apache.camel.component.mapstruct.MapStructMapperFinder</code> type.
+ *
+ * Group: advanced
+ *
+ * @param mapStructConverter the value to set
+ * @return the dsl builder
+ */
+ default MapstructComponentBuilder mapStructConverter(
+ org.apache.camel.component.mapstruct.MapStructMapperFinder mapStructConverter) {
+ doSetProperty("mapStructConverter", mapStructConverter);
+ return this;
+ }
+ }
+
+ class MapstructComponentBuilderImpl
+ extends
+ AbstractComponentBuilder<MapstructComponent>
+ implements
+ MapstructComponentBuilder {
+ @Override
+ protected MapstructComponent buildConcreteComponent() {
+ return new MapstructComponent();
+ }
+ @Override
+ protected boolean setPropertyOnComponent(
+ Component component,
+ String name,
+ Object value) {
+ switch (name) {
+ case "lazyStartProducer": ((MapstructComponent) component).setLazyStartProducer((boolean) value); return true;
+ case "mapperPackageName": ((MapstructComponent) component).setMapperPackageName((java.lang.String) value); return true;
+ case "autowiredEnabled": ((MapstructComponent) component).setAutowiredEnabled((boolean) value); return true;
+ case "mapStructConverter": ((MapstructComponent) component).setMapStructConverter((org.apache.camel.component.mapstruct.MapStructMapperFinder) value); return true;
+ default: return false;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/dsl/camel-componentdsl/src/generated/resources/metadata.json b/dsl/camel-componentdsl/src/generated/resources/metadata.json
index 8439fa41d55..54f2d93fc75 100644
--- a/dsl/camel-componentdsl/src/generated/resources/metadata.json
+++ b/dsl/camel-componentdsl/src/generated/resources/metadata.json
@@ -4745,6 +4745,28 @@
"producerOnly": false,
"lenientProperties": false
},
+ "MapstructComponentBuilderFactory": {
+ "kind": "component",
+ "name": "mapstruct",
+ "title": "MapStruct",
+ "description": "Type Conversion using Mapstruct",
+ "deprecated": false,
+ "firstVersion": "3.19.0",
+ "label": "transformation",
+ "javaType": "org.apache.camel.component.mapstruct.MapstructComponent",
+ "supportLevel": "Preview",
+ "groupId": "org.apache.camel",
+ "artifactId": "camel-mapstruct",
+ "version": "3.19.0-SNAPSHOT",
+ "scheme": "mapstruct",
+ "extendsScheme": "",
+ "syntax": "mapstruct:className",
+ "async": false,
+ "api": false,
+ "consumerOnly": false,
+ "producerOnly": true,
+ "lenientProperties": false
+ },
"MasterComponentBuilderFactory": {
"kind": "component",
"name": "master",
diff --git a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/EndpointBuilderFactory.java b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/EndpointBuilderFactory.java
index 4f8818da0d9..786a47abbe5 100644
--- a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/EndpointBuilderFactory.java
+++ b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/EndpointBuilderFactory.java
@@ -228,6 +228,7 @@ public interface EndpointBuilderFactory
org.apache.camel.builder.endpoint.dsl.MQ2EndpointBuilderFactory.MQ2Builders,
org.apache.camel.builder.endpoint.dsl.MSK2EndpointBuilderFactory.MSK2Builders,
org.apache.camel.builder.endpoint.dsl.MailEndpointBuilderFactory.MailBuilders,
+ org.apache.camel.builder.endpoint.dsl.MapstructEndpointBuilderFactory.MapstructBuilders,
org.apache.camel.builder.endpoint.dsl.MasterEndpointBuilderFactory.MasterBuilders,
org.apache.camel.builder.endpoint.dsl.MetricsEndpointBuilderFactory.MetricsBuilders,
org.apache.camel.builder.endpoint.dsl.MicroProfileMetricsEndpointBuilderFactory.MicroProfileMetricsBuilders,
diff --git a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/EndpointBuilders.java b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/EndpointBuilders.java
index 6b7e1f67b29..5a9ae8ff955 100644
--- a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/EndpointBuilders.java
+++ b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/EndpointBuilders.java
@@ -225,6 +225,7 @@ public interface EndpointBuilders
org.apache.camel.builder.endpoint.dsl.MQ2EndpointBuilderFactory,
org.apache.camel.builder.endpoint.dsl.MSK2EndpointBuilderFactory,
org.apache.camel.builder.endpoint.dsl.MailEndpointBuilderFactory,
+ org.apache.camel.builder.endpoint.dsl.MapstructEndpointBuilderFactory,
org.apache.camel.builder.endpoint.dsl.MasterEndpointBuilderFactory,
org.apache.camel.builder.endpoint.dsl.MetricsEndpointBuilderFactory,
org.apache.camel.builder.endpoint.dsl.MicroProfileMetricsEndpointBuilderFactory,
diff --git a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java
index 7bab9aa4001..037d7919951 100644
--- a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java
+++ b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java
@@ -9866,6 +9866,51 @@ public class StaticEndpointBuilders {
String path) {
return org.apache.camel.builder.endpoint.dsl.LumberjackEndpointBuilderFactory.endpointBuilder(componentName, path);
}
+ /**
+ * MapStruct (camel-mapstruct)
+ * Type Conversion using Mapstruct
+ *
+ * Category: transformation
+ * Since: 3.19
+ * Maven coordinates: org.apache.camel:camel-mapstruct
+ *
+ * Syntax: <code>mapstruct:className</code>
+ *
+ * Path parameter: className (required)
+ * The fully qualified class name of the POJO that mapstruct should convert
+ * to (target)
+ *
+ * @param path className
+ * @return the dsl builder
+ */
+ public static org.apache.camel.builder.endpoint.dsl.MapstructEndpointBuilderFactory.MapstructEndpointBuilder mapstruct(
+ String path) {
+ return org.apache.camel.builder.endpoint.dsl.MapstructEndpointBuilderFactory.endpointBuilder("mapstruct", path);
+ }
+ /**
+ * MapStruct (camel-mapstruct)
+ * Type Conversion using Mapstruct
+ *
+ * Category: transformation
+ * Since: 3.19
+ * Maven coordinates: org.apache.camel:camel-mapstruct
+ *
+ * Syntax: <code>mapstruct:className</code>
+ *
+ * Path parameter: className (required)
+ * The fully qualified class name of the POJO that mapstruct should convert
+ * to (target)
+ *
+ * @param componentName to use a custom component name for the endpoint
+ * instead of the default name
+ * @param path className
+ * @return the dsl builder
+ */
+ public static org.apache.camel.builder.endpoint.dsl.MapstructEndpointBuilderFactory.MapstructEndpointBuilder mapstruct(
+ String componentName,
+ String path) {
+ return org.apache.camel.builder.endpoint.dsl.MapstructEndpointBuilderFactory.endpointBuilder(componentName, path);
+ }
/**
* Master (camel-master)
* Have only a single consumer in a cluster consuming from a given endpoint;
diff --git a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/MapstructEndpointBuilderFactory.java b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/MapstructEndpointBuilderFactory.java
new file mode 100644
index 00000000000..db8c78aca53
--- /dev/null
+++ b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/MapstructEndpointBuilderFactory.java
@@ -0,0 +1,195 @@
+/*
+ * 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.builder.endpoint.dsl;
+
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.function.*;
+import java.util.stream.*;
+import javax.annotation.Generated;
+import org.apache.camel.builder.EndpointConsumerBuilder;
+import org.apache.camel.builder.EndpointProducerBuilder;
+import org.apache.camel.builder.endpoint.AbstractEndpointBuilder;
+
+/**
+ * Type Conversion using Mapstruct
+ *
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.EndpointDslMojo")
+public interface MapstructEndpointBuilderFactory {
+
+
+ /**
+ * Builder for endpoint for the MapStruct component.
+ */
+ public interface MapstructEndpointBuilder extends EndpointProducerBuilder {
+ default AdvancedMapstructEndpointBuilder advanced() {
+ return (AdvancedMapstructEndpointBuilder) this;
+ }
+ /**
+ * Whether there must exist a mapstruct converter to convert to the
+ * POJO.
+ *
+ * The option is a: <code>boolean</code> type.
+ *
+ * Default: true
+ * Group: producer
+ *
+ * @param mandatory the value to set
+ * @return the dsl builder
+ */
+ default MapstructEndpointBuilder mandatory(boolean mandatory) {
+ doSetProperty("mandatory", mandatory);
+ return this;
+ }
+ /**
+ * Whether there must exist a mapstruct converter to convert to the
+ * POJO.
+ *
+ * The option will be converted to a <code>boolean</code>
+ * type.
+ *
+ * Default: true
+ * Group: producer
+ *
+ * @param mandatory the value to set
+ * @return the dsl builder
+ */
+ default MapstructEndpointBuilder mandatory(String mandatory) {
+ doSetProperty("mandatory", mandatory);
+ return this;
+ }
+ }
+
+ /**
+ * Advanced builder for endpoint for the MapStruct component.
+ */
+ public interface AdvancedMapstructEndpointBuilder
+ extends
+ EndpointProducerBuilder {
+ default MapstructEndpointBuilder basic() {
+ return (MapstructEndpointBuilder) this;
+ }
+ /**
+ * Whether the producer should be started lazy (on the first message).
+ * By starting lazy you can use this to allow CamelContext and routes to
+ * startup in situations where a producer may otherwise fail during
+ * starting and cause the route to fail being started. By deferring this
+ * startup to be lazy then the startup failure can be handled during
+ * routing messages via Camel's routing error handlers. Beware that when
+ * the first message is processed then creating and starting the
+ * producer may take a little time and prolong the total processing time
+ * of the processing.
+ *
+ * The option is a: <code>boolean</code> type.
+ *
+ * Default: false
+ * Group: producer (advanced)
+ *
+ * @param lazyStartProducer the value to set
+ * @return the dsl builder
+ */
+ default AdvancedMapstructEndpointBuilder lazyStartProducer(
+ boolean lazyStartProducer) {
+ doSetProperty("lazyStartProducer", lazyStartProducer);
+ return this;
+ }
+ /**
+ * Whether the producer should be started lazy (on the first message).
+ * By starting lazy you can use this to allow CamelContext and routes to
+ * startup in situations where a producer may otherwise fail during
+ * starting and cause the route to fail being started. By deferring this
+ * startup to be lazy then the startup failure can be handled during
+ * routing messages via Camel's routing error handlers. Beware that when
+ * the first message is processed then creating and starting the
+ * producer may take a little time and prolong the total processing time
+ * of the processing.
+ *
+ * The option will be converted to a <code>boolean</code>
+ * type.
+ *
+ * Default: false
+ * Group: producer (advanced)
+ *
+ * @param lazyStartProducer the value to set
+ * @return the dsl builder
+ */
+ default AdvancedMapstructEndpointBuilder lazyStartProducer(
+ String lazyStartProducer) {
+ doSetProperty("lazyStartProducer", lazyStartProducer);
+ return this;
+ }
+ }
+
+ public interface MapstructBuilders {
+ /**
+ * MapStruct (camel-mapstruct)
+ * Type Conversion using Mapstruct
+ *
+ * Category: transformation
+ * Since: 3.19
+ * Maven coordinates: org.apache.camel:camel-mapstruct
+ *
+ * Syntax: <code>mapstruct:className</code>
+ *
+ * Path parameter: className (required)
+ * The fully qualified class name of the POJO that mapstruct should
+ * convert to (target)
+ *
+ * @param path className
+ * @return the dsl builder
+ */
+ default MapstructEndpointBuilder mapstruct(String path) {
+ return MapstructEndpointBuilderFactory.endpointBuilder("mapstruct", path);
+ }
+ /**
+ * MapStruct (camel-mapstruct)
+ * Type Conversion using Mapstruct
+ *
+ * Category: transformation
+ * Since: 3.19
+ * Maven coordinates: org.apache.camel:camel-mapstruct
+ *
+ * Syntax: <code>mapstruct:className</code>
+ *
+ * Path parameter: className (required)
+ * The fully qualified class name of the POJO that mapstruct should
+ * convert to (target)
+ *
+ * @param componentName to use a custom component name for the endpoint
+ * instead of the default name
+ * @param path className
+ * @return the dsl builder
+ */
+ default MapstructEndpointBuilder mapstruct(
+ String componentName,
+ String path) {
+ return MapstructEndpointBuilderFactory.endpointBuilder(componentName, path);
+ }
+ }
+ static MapstructEndpointBuilder endpointBuilder(
+ String componentName,
+ String path) {
+ class MapstructEndpointBuilderImpl extends AbstractEndpointBuilder implements MapstructEndpointBuilder, AdvancedMapstructEndpointBuilder {
+ public MapstructEndpointBuilderImpl(String path) {
+ super(componentName, path);
+ }
+ }
+ return new MapstructEndpointBuilderImpl(path);
+ }
+}
\ No newline at end of file
diff --git a/dsl/camel-kamelet-main/src/generated/resources/camel-component-known-dependencies.properties b/dsl/camel-kamelet-main/src/generated/resources/camel-component-known-dependencies.properties
index 38e9d07f25c..ad85ef003f8 100644
--- a/dsl/camel-kamelet-main/src/generated/resources/camel-component-known-dependencies.properties
+++ b/dsl/camel-kamelet-main/src/generated/resources/camel-component-known-dependencies.properties
@@ -223,6 +223,7 @@ org.apache.camel.component.log.LogComponent=camel:log
org.apache.camel.component.lucene.LuceneComponent=camel:lucene
org.apache.camel.component.lumberjack.LumberjackComponent=camel:lumberjack
org.apache.camel.component.mail.MailComponent=camel:mail
+org.apache.camel.component.mapstruct.MapstructComponent=camel:mapstruct
org.apache.camel.component.master.MasterComponent=camel:master
org.apache.camel.component.metrics.MetricsComponent=camel:metrics
org.apache.camel.component.micrometer.MicrometerComponent=camel:micrometer
diff --git a/parent/pom.xml b/parent/pom.xml
index eb72f16109a..77e888f36d6 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -364,6 +364,7 @@
<lucene-version>8.11.1</lucene-version>
<lucene-version-range>[8,9)</lucene-version-range>
<lightcouch-version>0.2.0</lightcouch-version>
+ <mapstruct-version>1.5.2.Final</mapstruct-version>
<!-- needed from tooling/archetypes -->
<!-- use antrun 1.6 as 1.7 fails with finding tools.jar on java on some platforms -->
<maven-antrun-plugin-version>1.6</maven-antrun-plugin-version>
@@ -1976,6 +1977,11 @@
<artifactId>camel-mail</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-mapstruct</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-master</artifactId>