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 6c7786cf4377 CAMEL-27272: camel-jackson, avro and protobuf - the Java
object data types keep a Map or a List when there is no X-Content-Class (#30477)
6c7786cf4377 is described below
commit 6c7786cf43772d34a2797618febffd48626f35c2
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Nov 20 08:32:54 2026 +0100
CAMEL-27272: camel-jackson, avro and protobuf - the Java object data types
keep a Map or a List when there is no X-Content-Class (#30477)
application-x-java-object (and avro-x-java-object and
protobuf-x-java-object,
which extend it) kept a POJO without the X-Content-Class exchange property,
but failed on a Map or a List with "Missing content class information",
although it is a Java object already and there is no class to read it into.
Without X-Content-Class, a Map or a List is now kept as it is and gets
Content-Type application/x-java-object. With the property it still fails,
as does a null body. transformerIn of the body types lists map and list,
and the catalog copies are regenerated. Jackson 2 and 3.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../catalog/transformers/application-x-java-object.json | 8 +++++---
.../camel/catalog/transformers/avro-x-java-object.json | 8 +++++---
.../catalog/transformers/protobuf-x-java-object.json | 8 +++++---
.../apache/camel/transformer/avro-x-java-object.json | 8 +++++---
.../avro/transform/AvroPojoDataTypeTransformer.java | 12 ++++++++----
.../avro/transform/AvroPojoDataTypeTransformerTest.java | 11 ++++++++++-
.../camel/transformer/protobuf-x-java-object.json | 8 +++++---
.../transform/ProtobufPojoDataTypeTransformer.java | 12 ++++++++----
.../transform/ProtobufPojoDataTypeTransformerTest.java | 11 ++++++++++-
.../camel/transformer/application-x-java-object.json | 8 +++++---
.../jackson/transform/JsonPojoDataTypeTransformer.java | 17 ++++++++++++++---
.../transform/JsonPojoDataTypeTransformerTest.java | 11 ++++++++++-
.../apache/camel/transformer/avro-x-java-object.json | 8 +++++---
.../avro/transform/AvroPojoDataTypeTransformer.java | 12 ++++++++----
.../avro/transform/AvroPojoDataTypeTransformerTest.java | 11 ++++++++++-
.../camel/transformer/protobuf-x-java-object.json | 8 +++++---
.../transform/ProtobufPojoDataTypeTransformer.java | 12 ++++++++----
.../transform/ProtobufPojoDataTypeTransformerTest.java | 11 ++++++++++-
.../camel/transformer/application-x-java-object.json | 8 +++++---
.../jackson3/transform/JsonPojoDataTypeTransformer.java | 17 ++++++++++++++---
.../transform/JsonPojoDataTypeTransformerTest.java | 11 ++++++++++-
21 files changed, 165 insertions(+), 55 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/application-x-java-object.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/application-x-java-object.json
index 270117ea8d8d..29a225e359b1 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/application-x-java-object.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/application-x-java-object.json
@@ -17,15 +17,17 @@
"bytes",
"stream",
"file",
- "pojo"
+ "pojo",
+ "map",
+ "list"
],
- "description": "Json read into the class of the X-Content-Class exchange
property, which a body other than a POJO needs: a POJO of that class, or any
POJO without it, is kept, and a Map, a List or a null body fail"
+ "description": "Json read into the class of the X-Content-Class exchange
property, which a body other than a POJO needs: a POJO of that class, or any
POJO without it, is kept, and so is a Map or a List without it; a Map or a List
with it, and a null body, fail"
},
"transformerOut": {
"carriers": [
"unknown"
],
- "description": "An object of the class of the X-Content-Class exchange
property"
+ "description": "An object of the class of the X-Content-Class exchange
property, or the POJO, Map or List as it was without it"
}
}
}
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/avro-x-java-object.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/avro-x-java-object.json
index 0d488b5eaa92..0d38fb11991c 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/avro-x-java-object.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/avro-x-java-object.json
@@ -17,15 +17,17 @@
"bytes",
"stream",
"file",
- "pojo"
+ "pojo",
+ "map",
+ "list"
],
- "description": "Json text or a JsonNode, or Avro binary with the Avro
schema in the X-Content-Schema exchange property, read into the class of the
X-Content-Class exchange property, which a body other than a POJO needs: a POJO
of that class, or any POJO without it, is kept, and a Map or a null body fail"
+ "description": "Json text or a JsonNode, or Avro binary with the Avro
schema in the X-Content-Schema exchange property, read into the class of the
X-Content-Class exchange property, which a body other than a POJO needs: a POJO
of that class, or any POJO without it, is kept, and so is a Map or a List
without it; a Map or a List with it, and a null body, fail"
},
"transformerOut": {
"carriers": [
"unknown"
],
- "description": "An object of the class of the X-Content-Class exchange
property"
+ "description": "An object of the class of the X-Content-Class exchange
property, or the POJO, Map or List as it was without it"
}
}
}
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/protobuf-x-java-object.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/protobuf-x-java-object.json
index ab1b1270e99f..f8b36f07805a 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/protobuf-x-java-object.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/protobuf-x-java-object.json
@@ -17,15 +17,17 @@
"bytes",
"stream",
"file",
- "pojo"
+ "pojo",
+ "map",
+ "list"
],
- "description": "Json text or a JsonNode, or Protobuf binary with the
Protobuf schema in the X-Content-Schema exchange property, read into the class
of the X-Content-Class exchange property, which a body other than a POJO needs:
a POJO of that class, or any POJO without it, is kept, and a Map or a null body
fail"
+ "description": "Json text or a JsonNode, or Protobuf binary with the
Protobuf schema in the X-Content-Schema exchange property, read into the class
of the X-Content-Class exchange property, which a body other than a POJO needs:
a POJO of that class, or any POJO without it, is kept, and so is a Map or a
List without it; a Map or a List with it, and a null body, fail"
},
"transformerOut": {
"carriers": [
"unknown"
],
- "description": "An object of the class of the X-Content-Class exchange
property"
+ "description": "An object of the class of the X-Content-Class exchange
property, or the POJO, Map or List as it was without it"
}
}
}
diff --git
a/components/camel-jackson-avro/src/generated/resources/META-INF/services/org/apache/camel/transformer/avro-x-java-object.json
b/components/camel-jackson-avro/src/generated/resources/META-INF/services/org/apache/camel/transformer/avro-x-java-object.json
index e679b539ff22..fee9e765933e 100644
---
a/components/camel-jackson-avro/src/generated/resources/META-INF/services/org/apache/camel/transformer/avro-x-java-object.json
+++
b/components/camel-jackson-avro/src/generated/resources/META-INF/services/org/apache/camel/transformer/avro-x-java-object.json
@@ -17,15 +17,17 @@
"bytes",
"stream",
"file",
- "pojo"
+ "pojo",
+ "map",
+ "list"
],
- "description": "Json text or a JsonNode, or Avro binary with the Avro
schema in the X-Content-Schema exchange property, read into the class of the
X-Content-Class exchange property, which a body other than a POJO needs: a POJO
of that class, or any POJO without it, is kept, and a Map or a null body fail"
+ "description": "Json text or a JsonNode, or Avro binary with the Avro
schema in the X-Content-Schema exchange property, read into the class of the
X-Content-Class exchange property, which a body other than a POJO needs: a POJO
of that class, or any POJO without it, is kept, and so is a Map or a List
without it; a Map or a List with it, and a null body, fail"
},
"transformerOut": {
"carriers": [
"unknown"
],
- "description": "An object of the class of the X-Content-Class exchange
property"
+ "description": "An object of the class of the X-Content-Class exchange
property, or the POJO, Map or List as it was without it"
}
}
}
diff --git
a/components/camel-jackson-avro/src/main/java/org/apache/camel/component/jackson/avro/transform/AvroPojoDataTypeTransformer.java
b/components/camel-jackson-avro/src/main/java/org/apache/camel/component/jackson/avro/transform/AvroPojoDataTypeTransformer.java
index 5e22ddf17e76..452c72b9ca6a 100644
---
a/components/camel-jackson-avro/src/main/java/org/apache/camel/component/jackson/avro/transform/AvroPojoDataTypeTransformer.java
+++
b/components/camel-jackson-avro/src/main/java/org/apache/camel/component/jackson/avro/transform/AvroPojoDataTypeTransformer.java
@@ -38,14 +38,18 @@ import org.apache.camel.spi.DataTypeTransformer;
*/
@DataTypeTransformer(name = "avro-x-java-object",
description = "Transforms from JSon to Java object using
Jackson Avro (supports content schema)")
-@BodyTypes(transformerIn = @BodyType(value = { Carrier.TEXT, Carrier.BYTES,
Carrier.STREAM, Carrier.FILE, Carrier.POJO },
+@BodyTypes(transformerIn = @BodyType(value = {
+ Carrier.TEXT, Carrier.BYTES, Carrier.STREAM, Carrier.FILE,
Carrier.POJO,
+ Carrier.MAP, Carrier.LIST },
description = "Json text or a JsonNode,
or Avro binary with the Avro schema in the"
+ " X-Content-Schema
exchange property, read into the class of the"
+ " X-Content-Class
exchange property, which a body other than a POJO"
- + " needs: a POJO of that
class, or any POJO without it, is kept, and a"
- + " Map or a null body
fail"),
+ + " needs: a POJO of that
class, or any POJO without it, is kept, and"
+ + " so is a Map or a List
without it; a Map or a List with it, and a"
+ + " null body, fail"),
transformerOut = @BodyType(value = Carrier.UNKNOWN,
- description = "An object of the class of
the X-Content-Class exchange property"))
+ description = "An object of the class of
the X-Content-Class exchange property, or"
+ + " the POJO, Map or List
as it was without it"))
public class AvroPojoDataTypeTransformer extends JsonPojoDataTypeTransformer {
@Override
diff --git
a/components/camel-jackson-avro/src/test/java/org/apache/camel/component/jackson/avro/transform/AvroPojoDataTypeTransformerTest.java
b/components/camel-jackson-avro/src/test/java/org/apache/camel/component/jackson/avro/transform/AvroPojoDataTypeTransformerTest.java
index f2d92aca2a00..9c5896993ea5 100644
---
a/components/camel-jackson-avro/src/test/java/org/apache/camel/component/jackson/avro/transform/AvroPojoDataTypeTransformerTest.java
+++
b/components/camel-jackson-avro/src/test/java/org/apache/camel/component/jackson/avro/transform/AvroPojoDataTypeTransformerTest.java
@@ -185,7 +185,8 @@ class AvroPojoDataTypeTransformerTest {
// CAMEL-25928: Json text or a JsonNode, or Avro binary as bytes, a
stream or a file, as transformerIn
// says, read into the class of the X-Content-Class property, which
transformerOut leaves unknown
BodyTypes bodyTypes =
AvroPojoDataTypeTransformer.class.getAnnotation(BodyTypes.class);
- Assertions.assertEquals(List.of(Carrier.TEXT, Carrier.BYTES,
Carrier.STREAM, Carrier.FILE, Carrier.POJO),
+ Assertions.assertEquals(
+ List.of(Carrier.TEXT, Carrier.BYTES, Carrier.STREAM,
Carrier.FILE, Carrier.POJO, Carrier.MAP, Carrier.LIST),
List.of(bodyTypes.transformerIn().value()));
Assertions.assertEquals(List.of(Carrier.UNKNOWN),
List.of(bodyTypes.transformerOut().value()));
String json = "{ \"name\": \"Goofy\", \"age\": 25 }";
@@ -207,6 +208,14 @@ class AvroPojoDataTypeTransformerTest {
kept.getMessage().setBody(body);
transformer.transform(kept.getMessage(), DataType.ANY, DataType.ANY);
Assertions.assertSame(body, kept.getMessage().getBody());
+ // CAMEL-27272: a Map or a List is kept without the X-Content-Class
property
+ for (Object data : List.of(Map.of("name", "Goofy"), List.of("Goofy",
"Pluto"))) {
+ Exchange exchange = new DefaultExchange(camelContext);
+ exchange.getMessage().setBody(data);
+ transformer.transform(exchange.getMessage(), DataType.ANY,
DataType.ANY);
+ Assertions.assertSame(data, exchange.getMessage().getBody());
+ Assertions.assertEquals("application/x-java-object",
exchange.getMessage().getHeader(Exchange.CONTENT_TYPE));
+ }
// a Map is no Json
Exchange other = new DefaultExchange(camelContext);
other.setProperty(SchemaHelper.CONTENT_SCHEMA, getSchema());
diff --git
a/components/camel-jackson-protobuf/src/generated/resources/META-INF/services/org/apache/camel/transformer/protobuf-x-java-object.json
b/components/camel-jackson-protobuf/src/generated/resources/META-INF/services/org/apache/camel/transformer/protobuf-x-java-object.json
index eb133e1b7fa2..0053ccc59884 100644
---
a/components/camel-jackson-protobuf/src/generated/resources/META-INF/services/org/apache/camel/transformer/protobuf-x-java-object.json
+++
b/components/camel-jackson-protobuf/src/generated/resources/META-INF/services/org/apache/camel/transformer/protobuf-x-java-object.json
@@ -17,15 +17,17 @@
"bytes",
"stream",
"file",
- "pojo"
+ "pojo",
+ "map",
+ "list"
],
- "description": "Json text or a JsonNode, or Protobuf binary with the
Protobuf schema in the X-Content-Schema exchange property, read into the class
of the X-Content-Class exchange property, which a body other than a POJO needs:
a POJO of that class, or any POJO without it, is kept, and a Map or a null body
fail"
+ "description": "Json text or a JsonNode, or Protobuf binary with the
Protobuf schema in the X-Content-Schema exchange property, read into the class
of the X-Content-Class exchange property, which a body other than a POJO needs:
a POJO of that class, or any POJO without it, is kept, and so is a Map or a
List without it; a Map or a List with it, and a null body, fail"
},
"transformerOut": {
"carriers": [
"unknown"
],
- "description": "An object of the class of the X-Content-Class exchange
property"
+ "description": "An object of the class of the X-Content-Class exchange
property, or the POJO, Map or List as it was without it"
}
}
}
diff --git
a/components/camel-jackson-protobuf/src/main/java/org/apache/camel/component/jackson/protobuf/transform/ProtobufPojoDataTypeTransformer.java
b/components/camel-jackson-protobuf/src/main/java/org/apache/camel/component/jackson/protobuf/transform/ProtobufPojoDataTypeTransformer.java
index 3bfa0f80a6d5..2fe1f763c560 100644
---
a/components/camel-jackson-protobuf/src/main/java/org/apache/camel/component/jackson/protobuf/transform/ProtobufPojoDataTypeTransformer.java
+++
b/components/camel-jackson-protobuf/src/main/java/org/apache/camel/component/jackson/protobuf/transform/ProtobufPojoDataTypeTransformer.java
@@ -38,14 +38,18 @@ import org.apache.camel.spi.DataTypeTransformer;
*/
@DataTypeTransformer(name = "protobuf-x-java-object",
description = "Transforms from JSon to Java object using
Jackson Protobuf (supports content schema)")
-@BodyTypes(transformerIn = @BodyType(value = { Carrier.TEXT, Carrier.BYTES,
Carrier.STREAM, Carrier.FILE, Carrier.POJO },
+@BodyTypes(transformerIn = @BodyType(value = {
+ Carrier.TEXT, Carrier.BYTES, Carrier.STREAM, Carrier.FILE,
Carrier.POJO,
+ Carrier.MAP, Carrier.LIST },
description = "Json text or a JsonNode,
or Protobuf binary with the Protobuf schema"
+ " in the X-Content-Schema
exchange property, read into the class of the"
+ " X-Content-Class
exchange property, which a body other than a POJO"
- + " needs: a POJO of that
class, or any POJO without it, is kept, and a"
- + " Map or a null body
fail"),
+ + " needs: a POJO of that
class, or any POJO without it, is kept, and"
+ + " so is a Map or a List
without it; a Map or a List with it, and a"
+ + " null body, fail"),
transformerOut = @BodyType(value = Carrier.UNKNOWN,
- description = "An object of the class of
the X-Content-Class exchange property"))
+ description = "An object of the class of
the X-Content-Class exchange property, or"
+ + " the POJO, Map or List
as it was without it"))
public class ProtobufPojoDataTypeTransformer extends
JsonPojoDataTypeTransformer {
@Override
diff --git
a/components/camel-jackson-protobuf/src/test/java/org/apache/camel/component/jackson/protobuf/transform/ProtobufPojoDataTypeTransformerTest.java
b/components/camel-jackson-protobuf/src/test/java/org/apache/camel/component/jackson/protobuf/transform/ProtobufPojoDataTypeTransformerTest.java
index a238eade2c68..b56f793ae357 100644
---
a/components/camel-jackson-protobuf/src/test/java/org/apache/camel/component/jackson/protobuf/transform/ProtobufPojoDataTypeTransformerTest.java
+++
b/components/camel-jackson-protobuf/src/test/java/org/apache/camel/component/jackson/protobuf/transform/ProtobufPojoDataTypeTransformerTest.java
@@ -182,7 +182,8 @@ class ProtobufPojoDataTypeTransformerTest {
// CAMEL-25928: Json text or a JsonNode, or Protobuf binary as bytes,
a stream or a file, as transformerIn
// says, read into the class of the X-Content-Class property, which
transformerOut leaves unknown
BodyTypes bodyTypes =
ProtobufPojoDataTypeTransformer.class.getAnnotation(BodyTypes.class);
- Assertions.assertEquals(List.of(Carrier.TEXT, Carrier.BYTES,
Carrier.STREAM, Carrier.FILE, Carrier.POJO),
+ Assertions.assertEquals(
+ List.of(Carrier.TEXT, Carrier.BYTES, Carrier.STREAM,
Carrier.FILE, Carrier.POJO, Carrier.MAP, Carrier.LIST),
List.of(bodyTypes.transformerIn().value()));
Assertions.assertEquals(List.of(Carrier.UNKNOWN),
List.of(bodyTypes.transformerOut().value()));
String json = "{ \"name\": \"Goofy\", \"age\": 25 }";
@@ -204,6 +205,14 @@ class ProtobufPojoDataTypeTransformerTest {
kept.getMessage().setBody(body);
transformer.transform(kept.getMessage(), DataType.ANY, DataType.ANY);
Assertions.assertSame(body, kept.getMessage().getBody());
+ // CAMEL-27272: a Map or a List is kept without the X-Content-Class
property
+ for (Object data : List.of(Map.of("name", "Goofy"), List.of("Goofy",
"Pluto"))) {
+ Exchange exchange = new DefaultExchange(camelContext);
+ exchange.getMessage().setBody(data);
+ transformer.transform(exchange.getMessage(), DataType.ANY,
DataType.ANY);
+ Assertions.assertSame(data, exchange.getMessage().getBody());
+ Assertions.assertEquals("application/x-java-object",
exchange.getMessage().getHeader(Exchange.CONTENT_TYPE));
+ }
// a Map is no Json
Exchange other = new DefaultExchange(camelContext);
other.setProperty(SchemaHelper.CONTENT_SCHEMA, getSchema());
diff --git
a/components/camel-jackson/src/generated/resources/META-INF/services/org/apache/camel/transformer/application-x-java-object.json
b/components/camel-jackson/src/generated/resources/META-INF/services/org/apache/camel/transformer/application-x-java-object.json
index d9078d39f649..40150ef2ec25 100644
---
a/components/camel-jackson/src/generated/resources/META-INF/services/org/apache/camel/transformer/application-x-java-object.json
+++
b/components/camel-jackson/src/generated/resources/META-INF/services/org/apache/camel/transformer/application-x-java-object.json
@@ -17,15 +17,17 @@
"bytes",
"stream",
"file",
- "pojo"
+ "pojo",
+ "map",
+ "list"
],
- "description": "Json read into the class of the X-Content-Class exchange
property, which a body other than a POJO needs: a POJO of that class, or any
POJO without it, is kept, and a Map, a List or a null body fail"
+ "description": "Json read into the class of the X-Content-Class exchange
property, which a body other than a POJO needs: a POJO of that class, or any
POJO without it, is kept, and so is a Map or a List without it; a Map or a List
with it, and a null body, fail"
},
"transformerOut": {
"carriers": [
"unknown"
],
- "description": "An object of the class of the X-Content-Class exchange
property"
+ "description": "An object of the class of the X-Content-Class exchange
property, or the POJO, Map or List as it was without it"
}
}
}
diff --git
a/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/transform/JsonPojoDataTypeTransformer.java
b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/transform/JsonPojoDataTypeTransformer.java
index 2c23d1cc812f..837ca3d27210 100644
---
a/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/transform/JsonPojoDataTypeTransformer.java
+++
b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/transform/JsonPojoDataTypeTransformer.java
@@ -19,6 +19,8 @@ package org.apache.camel.component.jackson.transform;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Collection;
+import java.util.Map;
import java.util.Optional;
import com.fasterxml.jackson.core.FormatSchema;
@@ -46,12 +48,16 @@ import org.apache.camel.util.ObjectHelper;
*/
@DataTypeTransformer(name = "application-x-java-object",
description = "Transforms from JSon to Java object using
Jackson (supports content schema)")
-@BodyTypes(transformerIn = @BodyType(value = { Carrier.TEXT, Carrier.BYTES,
Carrier.STREAM, Carrier.FILE, Carrier.POJO },
+@BodyTypes(transformerIn = @BodyType(value = {
+ Carrier.TEXT, Carrier.BYTES, Carrier.STREAM, Carrier.FILE,
Carrier.POJO,
+ Carrier.MAP, Carrier.LIST },
description = "Json read into the class
of the X-Content-Class exchange property,"
+ " which a body other than
a POJO needs: a POJO of that class, or any"
- + " POJO without it, is
kept, and a Map, a List or a null body fail"),
+ + " POJO without it, is
kept, and so is a Map or a List without it; a Map"
+ + " or a List with it, and
a null body, fail"),
transformerOut = @BodyType(value = Carrier.UNKNOWN,
- description = "An object of the class of
the X-Content-Class exchange property"))
+ description = "An object of the class of
the X-Content-Class exchange property, or"
+ + " the POJO, Map or List
as it was without it"))
public class JsonPojoDataTypeTransformer extends Transformer implements
CamelContextAware {
private CamelContext camelContext;
@@ -62,6 +68,11 @@ public class JsonPojoDataTypeTransformer extends Transformer
implements CamelCon
FormatSchema schema =
message.getExchange().getProperty(SchemaHelper.CONTENT_SCHEMA,
FormatSchema.class);
String contentClass =
SchemaHelper.resolveContentClass(message.getExchange(), null);
+ if (contentClass == null && (message.getBody() instanceof Map ||
message.getBody() instanceof Collection)) {
+ // a Map or a List is a Java object already, and there is no class
to read it into: it is kept
+ message.setHeader(Exchange.CONTENT_TYPE,
MimeType.JAVA_OBJECT.type());
+ return;
+ }
if (contentClass == null) {
throw new CamelExecutionException(
"Missing content class information for Java object data
type processing",
diff --git
a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/transform/JsonPojoDataTypeTransformerTest.java
b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/transform/JsonPojoDataTypeTransformerTest.java
index dc0db78e868f..e5291e80bfd3 100644
---
a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/transform/JsonPojoDataTypeTransformerTest.java
+++
b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/transform/JsonPojoDataTypeTransformerTest.java
@@ -151,7 +151,8 @@ class JsonPojoDataTypeTransformerTest {
// CAMEL-25928: Json as text, bytes, a stream, a file or a JsonNode,
as transformerIn says, read into the
// class of the X-Content-Class property, which transformerOut leaves
unknown
BodyTypes bodyTypes =
JsonPojoDataTypeTransformer.class.getAnnotation(BodyTypes.class);
- Assertions.assertEquals(List.of(Carrier.TEXT, Carrier.BYTES,
Carrier.STREAM, Carrier.FILE, Carrier.POJO),
+ Assertions.assertEquals(
+ List.of(Carrier.TEXT, Carrier.BYTES, Carrier.STREAM,
Carrier.FILE, Carrier.POJO, Carrier.MAP, Carrier.LIST),
List.of(bodyTypes.transformerIn().value()));
Assertions.assertEquals(List.of(Carrier.UNKNOWN),
List.of(bodyTypes.transformerOut().value()));
String json = "{ \"name\": \"Goofy\", \"age\": 25 }";
@@ -171,6 +172,14 @@ class JsonPojoDataTypeTransformerTest {
kept.getMessage().setBody(body);
transformer.transform(kept.getMessage(), DataType.ANY, DataType.ANY);
Assertions.assertSame(body, kept.getMessage().getBody());
+ // CAMEL-27272: a Map or a List is kept without the X-Content-Class
property
+ for (Object data : List.of(Map.of("name", "Goofy"), List.of("Goofy",
"Pluto"))) {
+ Exchange exchange = new DefaultExchange(camelContext);
+ exchange.getMessage().setBody(data);
+ transformer.transform(exchange.getMessage(), DataType.ANY,
DataType.ANY);
+ Assertions.assertSame(data, exchange.getMessage().getBody());
+ Assertions.assertEquals("application/x-java-object",
exchange.getMessage().getHeader(Exchange.CONTENT_TYPE));
+ }
// a Map is no Json
Exchange other = new DefaultExchange(camelContext);
other.setProperty(SchemaHelper.CONTENT_CLASS, Person.class.getName());
diff --git
a/components/camel-jackson3-avro/src/generated/resources/META-INF/services/org/apache/camel/transformer/avro-x-java-object.json
b/components/camel-jackson3-avro/src/generated/resources/META-INF/services/org/apache/camel/transformer/avro-x-java-object.json
index 0d488b5eaa92..0d38fb11991c 100644
---
a/components/camel-jackson3-avro/src/generated/resources/META-INF/services/org/apache/camel/transformer/avro-x-java-object.json
+++
b/components/camel-jackson3-avro/src/generated/resources/META-INF/services/org/apache/camel/transformer/avro-x-java-object.json
@@ -17,15 +17,17 @@
"bytes",
"stream",
"file",
- "pojo"
+ "pojo",
+ "map",
+ "list"
],
- "description": "Json text or a JsonNode, or Avro binary with the Avro
schema in the X-Content-Schema exchange property, read into the class of the
X-Content-Class exchange property, which a body other than a POJO needs: a POJO
of that class, or any POJO without it, is kept, and a Map or a null body fail"
+ "description": "Json text or a JsonNode, or Avro binary with the Avro
schema in the X-Content-Schema exchange property, read into the class of the
X-Content-Class exchange property, which a body other than a POJO needs: a POJO
of that class, or any POJO without it, is kept, and so is a Map or a List
without it; a Map or a List with it, and a null body, fail"
},
"transformerOut": {
"carriers": [
"unknown"
],
- "description": "An object of the class of the X-Content-Class exchange
property"
+ "description": "An object of the class of the X-Content-Class exchange
property, or the POJO, Map or List as it was without it"
}
}
}
diff --git
a/components/camel-jackson3-avro/src/main/java/org/apache/camel/component/jackson3/avro/transform/AvroPojoDataTypeTransformer.java
b/components/camel-jackson3-avro/src/main/java/org/apache/camel/component/jackson3/avro/transform/AvroPojoDataTypeTransformer.java
index e754ed5fbfcd..8fbf240eb3d3 100644
---
a/components/camel-jackson3-avro/src/main/java/org/apache/camel/component/jackson3/avro/transform/AvroPojoDataTypeTransformer.java
+++
b/components/camel-jackson3-avro/src/main/java/org/apache/camel/component/jackson3/avro/transform/AvroPojoDataTypeTransformer.java
@@ -38,14 +38,18 @@ import tools.jackson.databind.JsonNode;
*/
@DataTypeTransformer(name = "avro-x-java-object",
description = "Transforms from JSon to Java object using
Jackson Avro (supports content schema)")
-@BodyTypes(transformerIn = @BodyType(value = { Carrier.TEXT, Carrier.BYTES,
Carrier.STREAM, Carrier.FILE, Carrier.POJO },
+@BodyTypes(transformerIn = @BodyType(value = {
+ Carrier.TEXT, Carrier.BYTES, Carrier.STREAM, Carrier.FILE,
Carrier.POJO,
+ Carrier.MAP, Carrier.LIST },
description = "Json text or a JsonNode,
or Avro binary with the Avro schema in the"
+ " X-Content-Schema
exchange property, read into the class of the"
+ " X-Content-Class
exchange property, which a body other than a POJO"
- + " needs: a POJO of that
class, or any POJO without it, is kept, and a"
- + " Map or a null body
fail"),
+ + " needs: a POJO of that
class, or any POJO without it, is kept, and"
+ + " so is a Map or a List
without it; a Map or a List with it, and a"
+ + " null body, fail"),
transformerOut = @BodyType(value = Carrier.UNKNOWN,
- description = "An object of the class of
the X-Content-Class exchange property"))
+ description = "An object of the class of
the X-Content-Class exchange property, or"
+ + " the POJO, Map or List
as it was without it"))
public class AvroPojoDataTypeTransformer extends JsonPojoDataTypeTransformer {
@Override
diff --git
a/components/camel-jackson3-avro/src/test/java/org/apache/camel/component/jackson3/avro/transform/AvroPojoDataTypeTransformerTest.java
b/components/camel-jackson3-avro/src/test/java/org/apache/camel/component/jackson3/avro/transform/AvroPojoDataTypeTransformerTest.java
index 78e268f22c5b..04159eaa05e4 100644
---
a/components/camel-jackson3-avro/src/test/java/org/apache/camel/component/jackson3/avro/transform/AvroPojoDataTypeTransformerTest.java
+++
b/components/camel-jackson3-avro/src/test/java/org/apache/camel/component/jackson3/avro/transform/AvroPojoDataTypeTransformerTest.java
@@ -185,7 +185,8 @@ class AvroPojoDataTypeTransformerTest {
// CAMEL-25928: Json text or a JsonNode, or Avro binary as bytes, a
stream or a file, as transformerIn
// says, read into the class of the X-Content-Class property, which
transformerOut leaves unknown
BodyTypes bodyTypes =
AvroPojoDataTypeTransformer.class.getAnnotation(BodyTypes.class);
- Assertions.assertEquals(List.of(Carrier.TEXT, Carrier.BYTES,
Carrier.STREAM, Carrier.FILE, Carrier.POJO),
+ Assertions.assertEquals(
+ List.of(Carrier.TEXT, Carrier.BYTES, Carrier.STREAM,
Carrier.FILE, Carrier.POJO, Carrier.MAP, Carrier.LIST),
List.of(bodyTypes.transformerIn().value()));
Assertions.assertEquals(List.of(Carrier.UNKNOWN),
List.of(bodyTypes.transformerOut().value()));
String json = "{ \"name\": \"Goofy\", \"age\": 25 }";
@@ -207,6 +208,14 @@ class AvroPojoDataTypeTransformerTest {
kept.getMessage().setBody(body);
transformer.transform(kept.getMessage(), DataType.ANY, DataType.ANY);
Assertions.assertSame(body, kept.getMessage().getBody());
+ // CAMEL-27272: a Map or a List is kept without the X-Content-Class
property
+ for (Object data : List.of(Map.of("name", "Goofy"), List.of("Goofy",
"Pluto"))) {
+ Exchange exchange = new DefaultExchange(camelContext);
+ exchange.getMessage().setBody(data);
+ transformer.transform(exchange.getMessage(), DataType.ANY,
DataType.ANY);
+ Assertions.assertSame(data, exchange.getMessage().getBody());
+ Assertions.assertEquals("application/x-java-object",
exchange.getMessage().getHeader(Exchange.CONTENT_TYPE));
+ }
// a Map is no Json
Exchange other = new DefaultExchange(camelContext);
other.setProperty(SchemaHelper.CONTENT_SCHEMA, getSchema());
diff --git
a/components/camel-jackson3-protobuf/src/generated/resources/META-INF/services/org/apache/camel/transformer/protobuf-x-java-object.json
b/components/camel-jackson3-protobuf/src/generated/resources/META-INF/services/org/apache/camel/transformer/protobuf-x-java-object.json
index ab1b1270e99f..f8b36f07805a 100644
---
a/components/camel-jackson3-protobuf/src/generated/resources/META-INF/services/org/apache/camel/transformer/protobuf-x-java-object.json
+++
b/components/camel-jackson3-protobuf/src/generated/resources/META-INF/services/org/apache/camel/transformer/protobuf-x-java-object.json
@@ -17,15 +17,17 @@
"bytes",
"stream",
"file",
- "pojo"
+ "pojo",
+ "map",
+ "list"
],
- "description": "Json text or a JsonNode, or Protobuf binary with the
Protobuf schema in the X-Content-Schema exchange property, read into the class
of the X-Content-Class exchange property, which a body other than a POJO needs:
a POJO of that class, or any POJO without it, is kept, and a Map or a null body
fail"
+ "description": "Json text or a JsonNode, or Protobuf binary with the
Protobuf schema in the X-Content-Schema exchange property, read into the class
of the X-Content-Class exchange property, which a body other than a POJO needs:
a POJO of that class, or any POJO without it, is kept, and so is a Map or a
List without it; a Map or a List with it, and a null body, fail"
},
"transformerOut": {
"carriers": [
"unknown"
],
- "description": "An object of the class of the X-Content-Class exchange
property"
+ "description": "An object of the class of the X-Content-Class exchange
property, or the POJO, Map or List as it was without it"
}
}
}
diff --git
a/components/camel-jackson3-protobuf/src/main/java/org/apache/camel/component/jackson3/protobuf/transform/ProtobufPojoDataTypeTransformer.java
b/components/camel-jackson3-protobuf/src/main/java/org/apache/camel/component/jackson3/protobuf/transform/ProtobufPojoDataTypeTransformer.java
index 6c1409955d48..33d3777a8f04 100644
---
a/components/camel-jackson3-protobuf/src/main/java/org/apache/camel/component/jackson3/protobuf/transform/ProtobufPojoDataTypeTransformer.java
+++
b/components/camel-jackson3-protobuf/src/main/java/org/apache/camel/component/jackson3/protobuf/transform/ProtobufPojoDataTypeTransformer.java
@@ -38,14 +38,18 @@ import tools.jackson.databind.JsonNode;
*/
@DataTypeTransformer(name = "protobuf-x-java-object",
description = "Transforms from JSon to Java object using
Jackson Protobuf (supports content schema)")
-@BodyTypes(transformerIn = @BodyType(value = { Carrier.TEXT, Carrier.BYTES,
Carrier.STREAM, Carrier.FILE, Carrier.POJO },
+@BodyTypes(transformerIn = @BodyType(value = {
+ Carrier.TEXT, Carrier.BYTES, Carrier.STREAM, Carrier.FILE,
Carrier.POJO,
+ Carrier.MAP, Carrier.LIST },
description = "Json text or a JsonNode,
or Protobuf binary with the Protobuf schema"
+ " in the X-Content-Schema
exchange property, read into the class of the"
+ " X-Content-Class
exchange property, which a body other than a POJO"
- + " needs: a POJO of that
class, or any POJO without it, is kept, and a"
- + " Map or a null body
fail"),
+ + " needs: a POJO of that
class, or any POJO without it, is kept, and"
+ + " so is a Map or a List
without it; a Map or a List with it, and a"
+ + " null body, fail"),
transformerOut = @BodyType(value = Carrier.UNKNOWN,
- description = "An object of the class of
the X-Content-Class exchange property"))
+ description = "An object of the class of
the X-Content-Class exchange property, or"
+ + " the POJO, Map or List
as it was without it"))
public class ProtobufPojoDataTypeTransformer extends
JsonPojoDataTypeTransformer {
@Override
diff --git
a/components/camel-jackson3-protobuf/src/test/java/org/apache/camel/component/jackson3/protobuf/transform/ProtobufPojoDataTypeTransformerTest.java
b/components/camel-jackson3-protobuf/src/test/java/org/apache/camel/component/jackson3/protobuf/transform/ProtobufPojoDataTypeTransformerTest.java
index ae0c3060ef4b..96c9c8b7510e 100644
---
a/components/camel-jackson3-protobuf/src/test/java/org/apache/camel/component/jackson3/protobuf/transform/ProtobufPojoDataTypeTransformerTest.java
+++
b/components/camel-jackson3-protobuf/src/test/java/org/apache/camel/component/jackson3/protobuf/transform/ProtobufPojoDataTypeTransformerTest.java
@@ -182,7 +182,8 @@ class ProtobufPojoDataTypeTransformerTest {
// CAMEL-25928: Json text or a JsonNode, or Protobuf binary as bytes,
a stream or a file, as transformerIn
// says, read into the class of the X-Content-Class property, which
transformerOut leaves unknown
BodyTypes bodyTypes =
ProtobufPojoDataTypeTransformer.class.getAnnotation(BodyTypes.class);
- Assertions.assertEquals(List.of(Carrier.TEXT, Carrier.BYTES,
Carrier.STREAM, Carrier.FILE, Carrier.POJO),
+ Assertions.assertEquals(
+ List.of(Carrier.TEXT, Carrier.BYTES, Carrier.STREAM,
Carrier.FILE, Carrier.POJO, Carrier.MAP, Carrier.LIST),
List.of(bodyTypes.transformerIn().value()));
Assertions.assertEquals(List.of(Carrier.UNKNOWN),
List.of(bodyTypes.transformerOut().value()));
String json = "{ \"name\": \"Goofy\", \"age\": 25 }";
@@ -204,6 +205,14 @@ class ProtobufPojoDataTypeTransformerTest {
kept.getMessage().setBody(body);
transformer.transform(kept.getMessage(), DataType.ANY, DataType.ANY);
Assertions.assertSame(body, kept.getMessage().getBody());
+ // CAMEL-27272: a Map or a List is kept without the X-Content-Class
property
+ for (Object data : List.of(Map.of("name", "Goofy"), List.of("Goofy",
"Pluto"))) {
+ Exchange exchange = new DefaultExchange(camelContext);
+ exchange.getMessage().setBody(data);
+ transformer.transform(exchange.getMessage(), DataType.ANY,
DataType.ANY);
+ Assertions.assertSame(data, exchange.getMessage().getBody());
+ Assertions.assertEquals("application/x-java-object",
exchange.getMessage().getHeader(Exchange.CONTENT_TYPE));
+ }
// a Map is no Json
Exchange other = new DefaultExchange(camelContext);
other.setProperty(SchemaHelper.CONTENT_SCHEMA, getSchema());
diff --git
a/components/camel-jackson3/src/generated/resources/META-INF/services/org/apache/camel/transformer/application-x-java-object.json
b/components/camel-jackson3/src/generated/resources/META-INF/services/org/apache/camel/transformer/application-x-java-object.json
index 270117ea8d8d..29a225e359b1 100644
---
a/components/camel-jackson3/src/generated/resources/META-INF/services/org/apache/camel/transformer/application-x-java-object.json
+++
b/components/camel-jackson3/src/generated/resources/META-INF/services/org/apache/camel/transformer/application-x-java-object.json
@@ -17,15 +17,17 @@
"bytes",
"stream",
"file",
- "pojo"
+ "pojo",
+ "map",
+ "list"
],
- "description": "Json read into the class of the X-Content-Class exchange
property, which a body other than a POJO needs: a POJO of that class, or any
POJO without it, is kept, and a Map, a List or a null body fail"
+ "description": "Json read into the class of the X-Content-Class exchange
property, which a body other than a POJO needs: a POJO of that class, or any
POJO without it, is kept, and so is a Map or a List without it; a Map or a List
with it, and a null body, fail"
},
"transformerOut": {
"carriers": [
"unknown"
],
- "description": "An object of the class of the X-Content-Class exchange
property"
+ "description": "An object of the class of the X-Content-Class exchange
property, or the POJO, Map or List as it was without it"
}
}
}
diff --git
a/components/camel-jackson3/src/main/java/org/apache/camel/component/jackson3/transform/JsonPojoDataTypeTransformer.java
b/components/camel-jackson3/src/main/java/org/apache/camel/component/jackson3/transform/JsonPojoDataTypeTransformer.java
index 5531aaa25d4e..5ea11ddb88fe 100644
---
a/components/camel-jackson3/src/main/java/org/apache/camel/component/jackson3/transform/JsonPojoDataTypeTransformer.java
+++
b/components/camel-jackson3/src/main/java/org/apache/camel/component/jackson3/transform/JsonPojoDataTypeTransformer.java
@@ -19,6 +19,8 @@ package org.apache.camel.component.jackson3.transform;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Collection;
+import java.util.Map;
import java.util.Optional;
import org.apache.camel.CamelContext;
@@ -47,12 +49,16 @@ import tools.jackson.core.JacksonException;
*/
@DataTypeTransformer(name = "application-x-java-object",
description = "Transforms from JSon to Java object using
Jackson (supports content schema)")
-@BodyTypes(transformerIn = @BodyType(value = { Carrier.TEXT, Carrier.BYTES,
Carrier.STREAM, Carrier.FILE, Carrier.POJO },
+@BodyTypes(transformerIn = @BodyType(value = {
+ Carrier.TEXT, Carrier.BYTES, Carrier.STREAM, Carrier.FILE,
Carrier.POJO,
+ Carrier.MAP, Carrier.LIST },
description = "Json read into the class
of the X-Content-Class exchange property,"
+ " which a body other than
a POJO needs: a POJO of that class, or any"
- + " POJO without it, is
kept, and a Map, a List or a null body fail"),
+ + " POJO without it, is
kept, and so is a Map or a List without it; a Map"
+ + " or a List with it, and
a null body, fail"),
transformerOut = @BodyType(value = Carrier.UNKNOWN,
- description = "An object of the class of
the X-Content-Class exchange property"))
+ description = "An object of the class of
the X-Content-Class exchange property, or"
+ + " the POJO, Map or List
as it was without it"))
public class JsonPojoDataTypeTransformer extends Transformer implements
CamelContextAware {
private CamelContext camelContext;
@@ -63,6 +69,11 @@ public class JsonPojoDataTypeTransformer extends Transformer
implements CamelCon
FormatSchema schema =
message.getExchange().getProperty(SchemaHelper.CONTENT_SCHEMA,
FormatSchema.class);
String contentClass =
SchemaHelper.resolveContentClass(message.getExchange(), null);
+ if (contentClass == null && (message.getBody() instanceof Map ||
message.getBody() instanceof Collection)) {
+ // a Map or a List is a Java object already, and there is no class
to read it into: it is kept
+ message.setHeader(Exchange.CONTENT_TYPE,
MimeType.JAVA_OBJECT.type());
+ return;
+ }
if (contentClass == null) {
throw new CamelExecutionException(
"Missing content class information for Java object data
type processing",
diff --git
a/components/camel-jackson3/src/test/java/org/apache/camel/component/jackson3/transform/JsonPojoDataTypeTransformerTest.java
b/components/camel-jackson3/src/test/java/org/apache/camel/component/jackson3/transform/JsonPojoDataTypeTransformerTest.java
index 170ad85c72c3..50212b3abebb 100644
---
a/components/camel-jackson3/src/test/java/org/apache/camel/component/jackson3/transform/JsonPojoDataTypeTransformerTest.java
+++
b/components/camel-jackson3/src/test/java/org/apache/camel/component/jackson3/transform/JsonPojoDataTypeTransformerTest.java
@@ -162,7 +162,8 @@ class JsonPojoDataTypeTransformerTest {
// CAMEL-25928: Json as text, bytes, a stream, a file or a JsonNode,
as transformerIn says, read into the
// class of the X-Content-Class property, which transformerOut leaves
unknown
BodyTypes bodyTypes =
JsonPojoDataTypeTransformer.class.getAnnotation(BodyTypes.class);
- Assertions.assertEquals(List.of(Carrier.TEXT, Carrier.BYTES,
Carrier.STREAM, Carrier.FILE, Carrier.POJO),
+ Assertions.assertEquals(
+ List.of(Carrier.TEXT, Carrier.BYTES, Carrier.STREAM,
Carrier.FILE, Carrier.POJO, Carrier.MAP, Carrier.LIST),
List.of(bodyTypes.transformerIn().value()));
Assertions.assertEquals(List.of(Carrier.UNKNOWN),
List.of(bodyTypes.transformerOut().value()));
String json = "{ \"name\": \"Goofy\", \"age\": 25 }";
@@ -182,6 +183,14 @@ class JsonPojoDataTypeTransformerTest {
kept.getMessage().setBody(body);
transformer.transform(kept.getMessage(), DataType.ANY, DataType.ANY);
Assertions.assertSame(body, kept.getMessage().getBody());
+ // CAMEL-27272: a Map or a List is kept without the X-Content-Class
property
+ for (Object data : List.of(Map.of("name", "Goofy"), List.of("Goofy",
"Pluto"))) {
+ Exchange exchange = new DefaultExchange(camelContext);
+ exchange.getMessage().setBody(data);
+ transformer.transform(exchange.getMessage(), DataType.ANY,
DataType.ANY);
+ Assertions.assertSame(data, exchange.getMessage().getBody());
+ Assertions.assertEquals("application/x-java-object",
exchange.getMessage().getHeader(Exchange.CONTENT_TYPE));
+ }
// a Map is no Json
Exchange other = new DefaultExchange(camelContext);
other.setProperty(SchemaHelper.CONTENT_CLASS, Person.class.getName());