Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
3.18.1, 3.20.0
-
None
-
jdk11
-
Unknown
Description
I have been unsuccessful in declaring a java.util.List bean. According to camel-main documentation, a List bean should be declared using numeric keys in square brackets:
camel.beans.myprojects[0] = Camel camel.beans.myprojects[1] = Kafka camel.beans.myprojects[2] = Quarkus
This does, however, not actually declare a java.util.List, but a java.util.LinkedHashMap, instead.
Again, reproduction is easy:
@Test public void testBindBeansList() { Main main = new Main(); main.configure().addRoutesBuilder(new MyRouteBuilder()); // defining a list bean main.addProperty("camel.beans.myprojects[0]", "Camel"); main.addProperty("camel.beans.myprojects[1]", "Kafka"); main.addProperty("camel.beans.myprojects[2]", "Quarkus"); main.start(); CamelContext camelContext = main.getCamelContext(); assertNotNull(camelContext); Object bean = camelContext.getRegistry().lookupByName("myprojects"); assertNotNull(bean); assertInstanceOf(java.util.List.class, bean); java.util.List<?> list = (java.util.List<?>) bean; assertEquals(3, list.size()); assertEquals("Camel", list.get(0)); assertEquals("Kafka", list.get(1)); assertEquals("Quarkus", list.get(2)); main.stop(); }
There is a workaround, which is to use java.util.List#of, which is also more concise, but only possible if using Java 9 or above:
camel.beans.myprojects = #class:java.util.List#of("Camel", "Kafka", "Quarkus")