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 2023/08/23 10:46:50 UTC

[camel] branch camel-4.0.x updated: fix!: change way collection items are transformed into domain objects (#11182)

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

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


The following commit(s) were added to refs/heads/camel-4.0.x by this push:
     new 6b6105b7e95 fix!: change way collection items are transformed into domain objects (#11182)
6b6105b7e95 is described below

commit 6b6105b7e95b5818c9449ab7844018e9cd5a9f2f
Author: Claude Mamo <82...@users.noreply.github.com>
AuthorDate: Wed Aug 23 12:45:41 2023 +0200

    fix!: change way collection items are transformed into domain objects (#11182)
    
    * fix!: change way collection items are transformed into domain objects since currently it's broken (split is reading only the first item)
    
    disabled paging by default since some DHIS2 endpoints don't support pagination
    
    * fix: commit changes
---
 .../org/apache/camel/catalog/components/dhis2.json |  2 +-
 .../apache/camel/component/dhis2/api/Dhis2Get.java |  9 ++-
 .../camel/component/dhis2/api/Dhis2Resource.java   | 22 +++++++
 .../component/dhis2/api/ItemTypeConverter.java     | 69 ----------------------
 .../component/dhis2/api/Dhis2GetTestCase.java      | 60 ++++++++++++++-----
 .../camel/component/dhis2/Dhis2Converters.java     | 37 ++++++++++++
 .../component/dhis2/Dhis2ConvertersLoader.java     | 51 ++++++++++++++++
 .../dhis2/Dhis2GetEndpointConfiguration.java       |  2 +-
 .../dhis2/internal/Dhis2GetApiMethod.java          |  2 +-
 .../services/org/apache/camel/TypeConverterLoader  |  2 +
 .../org/apache/camel/component/dhis2/dhis2.json    |  2 +-
 .../src/main/docs/dhis2-component.adoc             |  7 ++-
 .../apache/camel/component/dhis2/Dhis2GetIT.java   | 24 ++++----
 .../apache/camel/component/dhis2/Dhis2PutIT.java   |  7 ++-
 .../apache/camel/component/dhis2/Environment.java  | 11 ++--
 15 files changed, 191 insertions(+), 116 deletions(-)

diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/dhis2.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/dhis2.json
index 67eff0af11d..868d415b2cd 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/dhis2.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/dhis2.json
@@ -63,7 +63,7 @@
   },
   "apis": {
     "delete": { "consumerOnly": false, "producerOnly": false, "description": "", "methods": { "resource": { "description": "", "signatures": [ "java.io.InputStream resource(String path, Object resource, java.util.Map<String, Object> queryParams)" ] } } },
-    "get": { "consumerOnly": false, "producerOnly": false, "description": "", "methods": { "collection": { "description": "", "signatures": [ "java.io.InputStream collection(String path, String arrayName, Boolean paging, String fields, String filter, org.apache.camel.component.dhis2.api.RootJunctionEnum rootJunction, java.util.Map<String, Object> queryParams)" ] }, "resource": { "description": "", "signatures": [ "java.io.InputStream resource(String path, String fields, String filter, or [...]
+    "get": { "consumerOnly": false, "producerOnly": false, "description": "", "methods": { "collection": { "description": "", "signatures": [ "java.util.Iterator<org.apache.camel.component.dhis2.api.Dhis2Resource> collection(String path, String arrayName, Boolean paging, String fields, String filter, org.apache.camel.component.dhis2.api.RootJunctionEnum rootJunction, java.util.Map<String, Object> queryParams)" ] }, "resource": { "description": "", "signatures": [ "java.io.InputStream res [...]
     "post": { "consumerOnly": false, "producerOnly": false, "description": "", "methods": { "resource": { "description": "", "signatures": [ "java.io.InputStream resource(String path, Object resource, java.util.Map<String, Object> queryParams)" ] } } },
     "put": { "consumerOnly": false, "producerOnly": false, "description": "", "methods": { "resource": { "description": "", "signatures": [ "java.io.InputStream resource(String path, Object resource, java.util.Map<String, Object> queryParams)" ] } } },
     "resourceTables": { "consumerOnly": false, "producerOnly": false, "description": "", "methods": { "analytics": { "description": "", "signatures": [ "void analytics(Boolean skipAggregate, Boolean skipEvents, Integer lastYears, Integer interval)" ] } } }
diff --git a/components/camel-dhis2/camel-dhis2-api/src/main/java/org/apache/camel/component/dhis2/api/Dhis2Get.java b/components/camel-dhis2/camel-dhis2-api/src/main/java/org/apache/camel/component/dhis2/api/Dhis2Get.java
index 0410bca6b8e..6103359c71f 100644
--- a/components/camel-dhis2/camel-dhis2-api/src/main/java/org/apache/camel/component/dhis2/api/Dhis2Get.java
+++ b/components/camel-dhis2/camel-dhis2-api/src/main/java/org/apache/camel/component/dhis2/api/Dhis2Get.java
@@ -17,10 +17,10 @@
 package org.apache.camel.component.dhis2.api;
 
 import java.io.InputStream;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.camel.support.InputStreamIterator;
 import org.hisp.dhis.integration.sdk.api.Dhis2Client;
 import org.hisp.dhis.integration.sdk.api.IterableDhis2Response;
 import org.hisp.dhis.integration.sdk.api.operation.GetOperation;
@@ -75,21 +75,20 @@ public class Dhis2Get {
         return getOperation;
     }
 
-    public InputStream collection(
+    public Iterator<Dhis2Resource> collection(
             String path, String arrayName, Boolean paging, String fields, String filter,
             RootJunctionEnum rootJunction,
             Map<String, Object> queryParams) {
         GetOperation getOperation = newGetOperation(path, fields, filter, rootJunction, queryParams);
 
         IterableDhis2Response iteratorDhis2Response;
-        if (paging == null || paging) {
+        if (paging != null && paging) {
             iteratorDhis2Response = getOperation.withPaging().transfer();
         } else {
             iteratorDhis2Response = getOperation.withoutPaging().transfer();
         }
 
-        Iterable<Map> iterable = iteratorDhis2Response.returnAs(Map.class, arrayName);
-        return new InputStreamIterator(new ItemTypeConverter(dhis2Client), iterable.iterator());
+        return iteratorDhis2Response.returnAs(Dhis2Resource.class, arrayName).iterator();
     }
 
 }
diff --git a/components/camel-dhis2/camel-dhis2-api/src/main/java/org/apache/camel/component/dhis2/api/Dhis2Resource.java b/components/camel-dhis2/camel-dhis2-api/src/main/java/org/apache/camel/component/dhis2/api/Dhis2Resource.java
new file mode 100644
index 00000000000..3ea72de30c7
--- /dev/null
+++ b/components/camel-dhis2/camel-dhis2-api/src/main/java/org/apache/camel/component/dhis2/api/Dhis2Resource.java
@@ -0,0 +1,22 @@
+/*
+ * 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.dhis2.api;
+
+import java.util.HashMap;
+
+public class Dhis2Resource extends HashMap<String, Object> {
+}
diff --git a/components/camel-dhis2/camel-dhis2-api/src/main/java/org/apache/camel/component/dhis2/api/ItemTypeConverter.java b/components/camel-dhis2/camel-dhis2-api/src/main/java/org/apache/camel/component/dhis2/api/ItemTypeConverter.java
deleted file mode 100644
index 32a6a16198f..00000000000
--- a/components/camel-dhis2/camel-dhis2-api/src/main/java/org/apache/camel/component/dhis2/api/ItemTypeConverter.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.dhis2.api;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.NoTypeConversionAvailableException;
-import org.apache.camel.TypeConversionException;
-import org.apache.camel.TypeConverter;
-import org.hisp.dhis.integration.sdk.api.Dhis2Client;
-
-public class ItemTypeConverter implements TypeConverter {
-
-    private final Dhis2Client dhis2Client;
-
-    public ItemTypeConverter(Dhis2Client dhis2Client) {
-        this.dhis2Client = dhis2Client;
-    }
-
-    @Override
-    public boolean allowNull() {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public <T> T convertTo(Class<T> type, Object value) throws TypeConversionException {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public <T> T convertTo(Class<T> type, Exchange exchange, Object value) throws TypeConversionException {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public <T> T mandatoryConvertTo(Class<T> type, Object value)
-            throws TypeConversionException, NoTypeConversionAvailableException {
-        return (T) dhis2Client.getConverterFactory().createConverter().convert(value).getBytes();
-    }
-
-    @Override
-    public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value)
-            throws TypeConversionException, NoTypeConversionAvailableException {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public <T> T tryConvertTo(Class<T> type, Object value) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public <T> T tryConvertTo(Class<T> type, Exchange exchange, Object value) {
-        throw new UnsupportedOperationException();
-    }
-}
diff --git a/components/camel-dhis2/camel-dhis2-api/src/test/java/org/apache/camel/component/dhis2/api/Dhis2GetTestCase.java b/components/camel-dhis2/camel-dhis2-api/src/test/java/org/apache/camel/component/dhis2/api/Dhis2GetTestCase.java
index 0a2e0688099..9cb958021bf 100644
--- a/components/camel-dhis2/camel-dhis2-api/src/test/java/org/apache/camel/component/dhis2/api/Dhis2GetTestCase.java
+++ b/components/camel-dhis2/camel-dhis2-api/src/test/java/org/apache/camel/component/dhis2/api/Dhis2GetTestCase.java
@@ -28,6 +28,7 @@ import org.hisp.dhis.integration.sdk.api.Dhis2Client;
 import org.hisp.dhis.integration.sdk.api.Dhis2Response;
 import org.hisp.dhis.integration.sdk.api.operation.GetOperation;
 import org.hisp.dhis.integration.sdk.internal.converter.JacksonConverterFactory;
+import org.hisp.dhis.integration.sdk.internal.operation.DefaultSimpleCollectOperation;
 import org.hisp.dhis.integration.sdk.internal.operation.page.DefaultPagingCollectOperation;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -72,6 +73,7 @@ public class Dhis2GetTestCase {
 
             }
         };
+        when(getOperation.withParameter(any(), any())).thenReturn(getOperation);
         when(getOperation.transfer()).thenReturn(dhis2Response);
         Dhis2Get dhis2Get = new Dhis2Get(dhis2Client);
         dhis2Get.resource(null, null, null, null, Map.of("foo", List.of("bar")));
@@ -96,6 +98,7 @@ public class Dhis2GetTestCase {
 
             }
         };
+        when(getOperation.withParameter(any(), any())).thenReturn(getOperation);
         when(getOperation.transfer()).thenReturn(dhis2Response);
         Dhis2Get dhis2Get = new Dhis2Get(dhis2Client);
         dhis2Get.resource(null, null, null, null, Map.of("foo", "bar"));
@@ -153,11 +156,7 @@ public class Dhis2GetTestCase {
     }
 
     @Test
-    public void testCollectionGivenMapOfStringsQueryParams() {
-        DefaultPagingCollectOperation defaultPagingCollectOperation = new DefaultPagingCollectOperation(
-                "https://play.dhis2.org/2.39.0.1", "", null, new JacksonConverterFactory(),
-                getOperation);
-
+    public void testCollectionGivenPagingIsTrue() {
         Dhis2Response dhis2Response = new Dhis2Response() {
             @Override
             public <T> T returnAs(Class<T> responseType) {
@@ -178,11 +177,44 @@ public class Dhis2GetTestCase {
 
             }
         };
+        when(getOperation.withParameter(any(), any())).thenReturn(getOperation);
+        when(getOperation.withParameter(any(), any())).thenReturn(getOperation);
         when(getOperation.transfer()).thenReturn(dhis2Response);
         when(getOperation.withPaging()).thenReturn(
                 new DefaultPagingCollectOperation(
                         "https://play.dhis2.org/2.39.0.1", "", null, new JacksonConverterFactory(), getOperation));
 
+        Dhis2Get dhis2Get = new Dhis2Get(dhis2Client);
+        dhis2Get.collection("bunnies", "bunnies", true, null, null, null, Map.of("foo", "bar"));
+        verify(getOperation, times(1)).withParameter("foo", "bar");
+    }
+
+    @Test
+    public void testCollectionGivenMapOfStringsQueryParams() {
+        Dhis2Response dhis2Response = new Dhis2Response() {
+            @Override
+            public <T> T returnAs(Class<T> responseType) {
+                return (T) Map.of("bunnies", new ArrayList<>());
+            }
+
+            @Override
+            public InputStream read() {
+                return new ByteArrayInputStream(new byte[] {});
+            }
+
+            @Override
+            public void close()
+                    throws IOException {
+
+            }
+        };
+        when(getOperation.withParameter(any(), any())).thenReturn(getOperation);
+        when(getOperation.withParameter(any(), any())).thenReturn(getOperation);
+        when(getOperation.transfer()).thenReturn(dhis2Response);
+        when(getOperation.withoutPaging()).thenReturn(
+                new DefaultSimpleCollectOperation(
+                        "https://play.dhis2.org/2.39.0.1", "", null, new JacksonConverterFactory(), getOperation));
+
         Dhis2Get dhis2Get = new Dhis2Get(dhis2Client);
         dhis2Get.collection("bunnies", "bunnies", null, null, null, null, Map.of("foo", "bar"));
         verify(getOperation, times(1)).withParameter("foo", "bar");
@@ -193,10 +225,7 @@ public class Dhis2GetTestCase {
         Dhis2Response dhis2Response = new Dhis2Response() {
             @Override
             public <T> T returnAs(Class<T> responseType) {
-                Page page = new Page();
-                page.setAdditionalProperty("bunnies", new ArrayList<>());
-
-                return (T) page;
+                return (T) Map.of("bunnies", new ArrayList<>());
             }
 
             @Override
@@ -209,9 +238,10 @@ public class Dhis2GetTestCase {
 
             }
         };
+        when(getOperation.withParameter(any(), any())).thenReturn(getOperation);
         when(getOperation.transfer()).thenReturn(dhis2Response);
-        when(getOperation.withPaging()).thenReturn(
-                new DefaultPagingCollectOperation(
+        when(getOperation.withoutPaging()).thenReturn(
+                new DefaultSimpleCollectOperation(
                         "https://play.dhis2.org/2.39.0.1", "", null,
                         new JacksonConverterFactory(), getOperation));
 
@@ -225,10 +255,7 @@ public class Dhis2GetTestCase {
         Dhis2Response dhis2Response = new Dhis2Response() {
             @Override
             public <T> T returnAs(Class<T> responseType) {
-                Page page = new Page();
-                page.setAdditionalProperty("bunnies", new ArrayList<>());
-
-                return (T) page;
+                return (T) Map.of("bunnies", new ArrayList<>());
             }
 
             @Override
@@ -241,8 +268,9 @@ public class Dhis2GetTestCase {
 
             }
         };
+        when(getOperation.withParameter(any(), any())).thenReturn(getOperation);
         when(getOperation.transfer()).thenReturn(dhis2Response);
-        when(getOperation.withPaging()).thenReturn(new DefaultPagingCollectOperation(
+        when(getOperation.withoutPaging()).thenReturn(new DefaultSimpleCollectOperation(
                 "https://play.dhis2.org/2.39.0.1", "", null, new JacksonConverterFactory(), getOperation));
 
         Dhis2Get dhis2Get = new Dhis2Get(dhis2Client);
diff --git a/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2Converters.java b/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2Converters.java
new file mode 100644
index 00000000000..739f0e978b1
--- /dev/null
+++ b/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2Converters.java
@@ -0,0 +1,37 @@
+/*
+ * 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.dhis2;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.dhis2.api.Dhis2Resource;
+import org.apache.camel.spi.TypeConverterRegistry;
+
+@Converter(generateLoader = true)
+public final class Dhis2Converters {
+    private static ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+    @Converter(fallback = true)
+    public static <T> T convertTo(Class<T> type, Exchange exchange, Object resource, TypeConverterRegistry registry) {
+        if (resource instanceof Dhis2Resource && type.getName().startsWith("org.hisp.dhis.api.model")) {
+            return OBJECT_MAPPER.convertValue(resource, type);
+        } else {
+            return null;
+        }
+    }
+}
\ No newline at end of file
diff --git a/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2ConvertersLoader.java b/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2ConvertersLoader.java
new file mode 100644
index 00000000000..c8b67855fa6
--- /dev/null
+++ b/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2ConvertersLoader.java
@@ -0,0 +1,51 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.component.dhis2;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.DeferredContextBinding;
+import org.apache.camel.Exchange;
+import org.apache.camel.TypeConversionException;
+import org.apache.camel.TypeConverterLoaderException;
+import org.apache.camel.spi.TypeConverterLoader;
+import org.apache.camel.spi.TypeConverterRegistry;
+import org.apache.camel.support.SimpleTypeConverter;
+import org.apache.camel.support.TypeConverterSupport;
+import org.apache.camel.util.DoubleMap;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+@DeferredContextBinding
+public final class Dhis2ConvertersLoader implements TypeConverterLoader, CamelContextAware {
+
+    private CamelContext camelContext;
+
+    public Dhis2ConvertersLoader() {
+    }
+
+    @Override
+    public void setCamelContext(CamelContext camelContext) {
+        this.camelContext = camelContext;
+    }
+
+    @Override
+    public CamelContext getCamelContext() {
+        return camelContext;
+    }
+
+    @Override
+    public void load(TypeConverterRegistry registry) throws TypeConverterLoaderException {
+        registerFallbackConverters(registry);
+    }
+
+    private void registerFallbackConverters(TypeConverterRegistry registry) {
+        addFallbackTypeConverter(registry, false, false, (type, exchange, value) -> org.apache.camel.component.dhis2.Dhis2Converters.convertTo(type, exchange, value, registry));
+    }
+
+    private static void addFallbackTypeConverter(TypeConverterRegistry registry, boolean allowNull, boolean canPromote, SimpleTypeConverter.ConversionMethod method) { 
+        registry.addFallbackTypeConverter(new SimpleTypeConverter(allowNull, method), canPromote);
+    }
+
+}
diff --git a/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2GetEndpointConfiguration.java b/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2GetEndpointConfiguration.java
index c6fca4984f8..f256c530f01 100644
--- a/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2GetEndpointConfiguration.java
+++ b/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2GetEndpointConfiguration.java
@@ -15,7 +15,7 @@ import org.apache.camel.spi.UriParams;
  */
 @ApiParams(apiName = "get", 
            description = "",
-           apiMethods = {@ApiMethod(methodName = "collection", signatures={"java.io.InputStream collection(String path, String arrayName, Boolean paging, String fields, String filter, org.apache.camel.component.dhis2.api.RootJunctionEnum rootJunction, java.util.Map<String, Object> queryParams)"}), @ApiMethod(methodName = "resource", signatures={"java.io.InputStream resource(String path, String fields, String filter, org.apache.camel.component.dhis2.api.RootJunctionEnum rootJunction, java [...]
+           apiMethods = {@ApiMethod(methodName = "collection", signatures={"java.util.Iterator<org.apache.camel.component.dhis2.api.Dhis2Resource> collection(String path, String arrayName, Boolean paging, String fields, String filter, org.apache.camel.component.dhis2.api.RootJunctionEnum rootJunction, java.util.Map<String, Object> queryParams)"}), @ApiMethod(methodName = "resource", signatures={"java.io.InputStream resource(String path, String fields, String filter, org.apache.camel.comp [...]
 @UriParams
 @Configurer(extended = true)
 public final class Dhis2GetEndpointConfiguration extends Dhis2Configuration {
diff --git a/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/internal/Dhis2GetApiMethod.java b/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/internal/Dhis2GetApiMethod.java
index eba3705f7ca..2448902473b 100644
--- a/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/internal/Dhis2GetApiMethod.java
+++ b/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/internal/Dhis2GetApiMethod.java
@@ -20,7 +20,7 @@ import static org.apache.camel.support.component.ApiMethodArg.arg;
 public enum Dhis2GetApiMethod implements ApiMethod {
 
     COLLECTION(
-        java.io.InputStream.class,
+        java.util.Iterator.class,
         "collection",
         arg("path", String.class),
         arg("arrayName", String.class),
diff --git a/components/camel-dhis2/camel-dhis2-component/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader b/components/camel-dhis2/camel-dhis2-component/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
new file mode 100644
index 00000000000..c5620f6c98c
--- /dev/null
+++ b/components/camel-dhis2/camel-dhis2-component/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+org.apache.camel.component.dhis2.Dhis2ConvertersLoader
diff --git a/components/camel-dhis2/camel-dhis2-component/src/generated/resources/org/apache/camel/component/dhis2/dhis2.json b/components/camel-dhis2/camel-dhis2-component/src/generated/resources/org/apache/camel/component/dhis2/dhis2.json
index 67eff0af11d..868d415b2cd 100644
--- a/components/camel-dhis2/camel-dhis2-component/src/generated/resources/org/apache/camel/component/dhis2/dhis2.json
+++ b/components/camel-dhis2/camel-dhis2-component/src/generated/resources/org/apache/camel/component/dhis2/dhis2.json
@@ -63,7 +63,7 @@
   },
   "apis": {
     "delete": { "consumerOnly": false, "producerOnly": false, "description": "", "methods": { "resource": { "description": "", "signatures": [ "java.io.InputStream resource(String path, Object resource, java.util.Map<String, Object> queryParams)" ] } } },
-    "get": { "consumerOnly": false, "producerOnly": false, "description": "", "methods": { "collection": { "description": "", "signatures": [ "java.io.InputStream collection(String path, String arrayName, Boolean paging, String fields, String filter, org.apache.camel.component.dhis2.api.RootJunctionEnum rootJunction, java.util.Map<String, Object> queryParams)" ] }, "resource": { "description": "", "signatures": [ "java.io.InputStream resource(String path, String fields, String filter, or [...]
+    "get": { "consumerOnly": false, "producerOnly": false, "description": "", "methods": { "collection": { "description": "", "signatures": [ "java.util.Iterator<org.apache.camel.component.dhis2.api.Dhis2Resource> collection(String path, String arrayName, Boolean paging, String fields, String filter, org.apache.camel.component.dhis2.api.RootJunctionEnum rootJunction, java.util.Map<String, Object> queryParams)" ] }, "resource": { "description": "", "signatures": [ "java.io.InputStream res [...]
     "post": { "consumerOnly": false, "producerOnly": false, "description": "", "methods": { "resource": { "description": "", "signatures": [ "java.io.InputStream resource(String path, Object resource, java.util.Map<String, Object> queryParams)" ] } } },
     "put": { "consumerOnly": false, "producerOnly": false, "description": "", "methods": { "resource": { "description": "", "signatures": [ "java.io.InputStream resource(String path, Object resource, java.util.Map<String, Object> queryParams)" ] } } },
     "resourceTables": { "consumerOnly": false, "producerOnly": false, "description": "", "methods": { "analytics": { "description": "", "signatures": [ "void analytics(Boolean skipAggregate, Boolean skipEvents, Integer lastYears, Integer interval)" ] } } }
diff --git a/components/camel-dhis2/camel-dhis2-component/src/main/docs/dhis2-component.adoc b/components/camel-dhis2/camel-dhis2-component/src/main/docs/dhis2-component.adoc
index b90930ca418..e36cd79a47f 100644
--- a/components/camel-dhis2/camel-dhis2-component/src/main/docs/dhis2-component.adoc
+++ b/components/camel-dhis2/camel-dhis2-component/src/main/docs/dhis2-component.adoc
@@ -122,7 +122,8 @@ public class MyRouteBuilder extends RouteBuilder {
     public void configure() {
         from("direct:getCollection")
             .to("dhis2://get/collection?path=organisationUnits&arrayName=organisationUnits&username=admin&password=district&baseApiUrl=https://play.dhis2.org/2.39.1/api")
-            .split().body().unmarshal().json(org.hisp.dhis.api.model.v2_39_1.OrganisationUnit.class).log("${body}");
+            .split().body()
+            .convertBody(org.hisp.dhis.api.model.v2_39_1.OrganisationUnit.class).log("${body}");
     }
 }
 ----
@@ -141,7 +142,7 @@ public class MyRouteBuilder extends RouteBuilder {
         from("direct:getCollection")
             .to("dhis2://get/collection?path=organisationUnits&fields=code&arrayName=organisationUnits&username=admin&password=district&baseApiUrl=https://play.dhis2.org/2.39.1/api")
             .split().body()
-            .unmarshal().json(org.hisp.dhis.api.model.v2_39_1.OrganisationUnit.class)
+            .convertBody(org.hisp.dhis.api.model.v2_39_1.OrganisationUnit.class)
             .log("${body}");
     }
 }
@@ -161,7 +162,7 @@ public class MyRouteBuilder extends RouteBuilder {
         from("direct:getCollection")
             .to("dhis2://get/collection?path=users&filter=phoneNumber:!null:&arrayName=users&username=admin&password=district&baseApiUrl=https://play.dhis2.org/2.39.1/api")
             .split().body()
-            .unmarshal().json(org.hisp.dhis.api.model.v2_39_1.User.class)
+            .convertBody(org.hisp.dhis.api.model.v2_39_1.User.class)
             .log("${body}");
     }
 }
diff --git a/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2GetIT.java b/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2GetIT.java
index 6870dc21718..101dc3f281c 100644
--- a/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2GetIT.java
+++ b/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2GetIT.java
@@ -20,16 +20,19 @@
 package org.apache.camel.component.dhis2;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.dhis2.internal.Dhis2ApiCollection;
 import org.apache.camel.component.dhis2.internal.Dhis2GetApiMethod;
+import org.apache.camel.processor.aggregate.GroupedBodyAggregationStrategy;
 import org.hisp.dhis.api.model.v2_39_1.OrganisationUnit;
 import org.junit.jupiter.api.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 /**
@@ -41,8 +44,8 @@ public class Dhis2GetIT extends AbstractDhis2TestSupport {
     private static final String PATH_PREFIX = Dhis2ApiCollection.getCollection().getApiName(Dhis2GetApiMethod.class).getName();
 
     @Test
-    public void testCollection() throws Exception {
-        final Map<String, Object> headers = new HashMap<String, Object>();
+    public void testCollection() {
+        final Map<String, Object> headers = new HashMap<>();
         headers.put("CamelDhis2.path", "organisationUnits");
         headers.put("CamelDhis2.arrayName", "organisationUnits");
         headers.put("CamelDhis2.paging", true);
@@ -50,16 +53,16 @@ public class Dhis2GetIT extends AbstractDhis2TestSupport {
         headers.put("CamelDhis2.filter", null);
         headers.put("CamelDhis2.queryParams", new HashMap<>());
 
-        final Object result = requestBodyAndHeaders("direct://COLLECTION", null, headers);
+        final List<OrganisationUnit> result = requestBodyAndHeaders("direct://COLLECTION", null, headers);
 
-        assertNotNull(result, "collection result");
+        assertEquals(2, result.size());
         LOG.debug("collection: {}", result);
     }
 
     @Test
-    public void testResource() throws Exception {
-        final Map<String, Object> headers = new HashMap<String, Object>();
-        headers.put("CamelDhis2.path", String.format("organisationUnits/%s", Environment.ORG_UNIT_ID));
+    public void testResource() {
+        final Map<String, Object> headers = new HashMap<>();
+        headers.put("CamelDhis2.path", String.format("organisationUnits/%s", Environment.ORG_UNIT_ID_UNDER_TEST));
         headers.put("CamelDhis2.fields", null);
         headers.put("CamelDhis2.filter", null);
         headers.put("CamelDhis2.queryParams", null);
@@ -76,14 +79,13 @@ public class Dhis2GetIT extends AbstractDhis2TestSupport {
             public void configure() {
                 // test route for collection
                 from("direct://COLLECTION")
-                        .to("dhis2://" + PATH_PREFIX + "/collection").split().body()
-                        .unmarshal()
-                        .json(OrganisationUnit.class);
+                        .to("dhis2://" + PATH_PREFIX + "/collection")
+                        .split().body().aggregationStrategy(new GroupedBodyAggregationStrategy())
+                        .convertBodyTo(OrganisationUnit.class);
 
                 // test route for resource
                 from("direct://RESOURCE")
                         .to("dhis2://" + PATH_PREFIX + "/resource");
-
             }
         };
     }
diff --git a/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2PutIT.java b/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2PutIT.java
index 64f421c9097..9b7faaa3f1a 100644
--- a/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2PutIT.java
+++ b/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2PutIT.java
@@ -56,15 +56,16 @@ public class Dhis2PutIT extends AbstractDhis2TestSupport {
     private void putResource(String endpointUri) {
         final Map<String, Object> headers = new HashMap<>();
         // parameter type is String
-        headers.put("CamelDhis2.path", String.format("organisationUnits/%s", Environment.ORG_UNIT_ID));
+        headers.put("CamelDhis2.path", String.format("organisationUnits/%s", Environment.ORG_UNIT_ID_UNDER_TEST));
         // parameter type is java.util.Map
         headers.put("CamelDhis2.queryParams", new HashMap<>());
 
         String name = RandomStringUtils.randomAlphabetic(8);
         final java.io.InputStream result = requestBodyAndHeaders(endpointUri,
                 new OrganisationUnit().withName(name).withShortName(name).withOpeningDate(new Date()), headers);
-        OrganisationUnit organisationUnit = Environment.DHIS2_CLIENT.get("organisationUnits/{id}", Environment.ORG_UNIT_ID)
-                .transfer().returnAs(OrganisationUnit.class);
+        OrganisationUnit organisationUnit
+                = Environment.DHIS2_CLIENT.get("organisationUnits/{id}", Environment.ORG_UNIT_ID_UNDER_TEST)
+                        .transfer().returnAs(OrganisationUnit.class);
         assertEquals(name, organisationUnit.getName().get());
 
         assertNotNull(result, "resource result");
diff --git a/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Environment.java b/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Environment.java
index 625d1be0f36..3584747bbee 100644
--- a/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Environment.java
+++ b/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Environment.java
@@ -36,7 +36,7 @@ public final class Environment {
 
     public static final Dhis2Client DHIS2_CLIENT;
 
-    public static final String ORG_UNIT_ID;
+    public static final String ORG_UNIT_ID_UNDER_TEST;
 
     private static final Network NETWORK = Network.newNetwork();
 
@@ -74,13 +74,14 @@ public final class Environment {
                         .getFirstMappedPort() + "/api",
                 "admin", "district").build();
 
-        ORG_UNIT_ID = createOrgUnit();
+        createOrgUnit("EvilCorp");
+        ORG_UNIT_ID_UNDER_TEST = createOrgUnit("Acme");
         createOrgUnitLevel();
-        addOrgUnitToUser(ORG_UNIT_ID);
+        addOrgUnitToUser(ORG_UNIT_ID_UNDER_TEST);
     }
 
-    private static String createOrgUnit() {
-        OrganisationUnit organisationUnit = new OrganisationUnit().withName("Acme").withShortName("Acme")
+    private static String createOrgUnit(String name) {
+        OrganisationUnit organisationUnit = new OrganisationUnit().withName(name).withShortName(name)
                 .withOpeningDate(new Date());
 
         return (String) ((Map<String, Object>) DHIS2_CLIENT.post("organisationUnits").withResource(organisationUnit)