[ 
https://issues.apache.org/jira/browse/CAMEL-18856?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen resolved CAMEL-18856.
---------------------------------
    Resolution: Fixed

Thanks for reporting and the test case

> camel-main - Unable to declare java.util.List bean
> --------------------------------------------------
>
>                 Key: CAMEL-18856
>                 URL: https://issues.apache.org/jira/browse/CAMEL-18856
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-main
>    Affects Versions: 3.18.1, 3.20.0
>         Environment: jdk11
>            Reporter: Christian Schubert-Huff
>            Assignee: Claus Ibsen
>            Priority: Minor
>             Fix For: 3.20.2, 3.21.0
>
>
> 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:
> {noformat}
> camel.beans.myprojects[0] = Camel
> camel.beans.myprojects[1] = Kafka
> camel.beans.myprojects[2] = Quarkus
> {noformat}
> This does, however, not actually declare a java.util.List, but a 
> java.util.LinkedHashMap, instead.
> Again, reproduction is easy:
> {code:java}
> @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();
> } {code}
> 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:
> {noformat}
> camel.beans.myprojects = #class:java.util.List#of("Camel", "Kafka", 
> "Quarkus"){noformat}
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to