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 2025/10/16 13:32:58 UTC
(camel) branch trytc created (now 2fb928efda77)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a change to branch trytc
in repository https://gitbox.apache.org/repos/asf/camel.git
at 2fb928efda77 CAMEL-22564: camel-core - Using try converter should not record a miss
This branch includes the following new commits:
new 2fb928efda77 CAMEL-22564: camel-core - Using try converter should not record a miss
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(camel) 01/01: CAMEL-22564: camel-core - Using try converter should not record a miss
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch trytc
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 2fb928efda779e5ff5fc6186fe8cee8a254cc0ec
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Oct 16 15:32:37 2025 +0200
CAMEL-22564: camel-core - Using try converter should not record a miss
---
.../impl/converter/CoreTypeConverterRegistry.java | 4 +++-
.../TypeConverterRegistryMissesThenAddTest.java | 23 ++++++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/converter/CoreTypeConverterRegistry.java b/core/camel-base/src/main/java/org/apache/camel/impl/converter/CoreTypeConverterRegistry.java
index 47494e5efc36..082e83ed2762 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/converter/CoreTypeConverterRegistry.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/converter/CoreTypeConverterRegistry.java
@@ -410,7 +410,9 @@ public abstract class CoreTypeConverterRegistry extends ServiceSupport implement
return objConverter.convertTo(type, exchange, value);
}
- converters.put(typeConvertible, MISS_CONVERTER);
+ if (!tryConvert) {
+ converters.put(typeConvertible, MISS_CONVERTER);
+ }
// Could not find suitable conversion, so return Void to indicate not found
return TypeConverter.MISS_VALUE;
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/TypeConverterRegistryMissesThenAddTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/TypeConverterRegistryMissesThenAddTest.java
index ddede7a5d833..4134176924a4 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/TypeConverterRegistryMissesThenAddTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/TypeConverterRegistryMissesThenAddTest.java
@@ -28,8 +28,11 @@ public class TypeConverterRegistryMissesThenAddTest {
public void testMissThenAddTypeConverter() {
DefaultCamelContext context = new DefaultCamelContext();
+ int before = context.getTypeConverterRegistry().size();
MyOrder order = context.getTypeConverter().convertTo(MyOrder.class, "123");
assertNull(order);
+ int after = context.getTypeConverterRegistry().size();
+ assertTrue(after > before); // should add miss converter marker
// add missing type converter
context.getTypeConverterRegistry().addTypeConverter(MyOrder.class, String.class, new MyOrderTypeConverter());
@@ -40,6 +43,26 @@ public class TypeConverterRegistryMissesThenAddTest {
assertEquals(123, order.getId());
}
+ @Test
+ public void testTryMiss() {
+ DefaultCamelContext context = new DefaultCamelContext();
+
+ int before = context.getTypeConverterRegistry().size();
+ MyOrder order = context.getTypeConverter().tryConvertTo(MyOrder.class, "456");
+ assertNull(order);
+ int after = context.getTypeConverterRegistry().size();
+ // we only try to convert so no miss marker
+ assertEquals(before, after);
+
+ // add missing type converter
+ context.getTypeConverterRegistry().addTypeConverter(MyOrder.class, String.class, new MyOrderTypeConverter());
+
+ // this time it should work
+ order = context.getTypeConverter().convertTo(MyOrder.class, "456");
+ assertNotNull(order);
+ assertEquals(456, order.getId());
+ }
+
private static class MyOrder {
private int id;