Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-18856

camel-main - Unable to declare java.util.List bean

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 3.18.1, 3.20.0
    • 3.20.2, 3.21.0, 4.0-M1, 4.0.0
    • camel-main
    • 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")

       

      Attachments

        Activity

          People

            davsclaus Claus Ibsen
            chrissh Christian Schubert-Huff
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: