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

Bindy ignores bean class type



    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.10.3
    • Fix Version/s: 2.16.0
    • Component/s: camel-bindy
    • Labels:
    • Estimated Complexity:


      It looks like camel-bindy does not take into account the class specified in the method:

      bindy(BindyType.Csv, MyCamelBeans.TEST.class)

      I have class MyCamelBeans which includes several "bindies" among which I have a really simple MyCamelBeans.TEST:

      class MyCamelBeans {
      public static final class TEST

      { @DataField(trim=true,pos= 1) public String tradingDate; @DataField(trim=true,pos= 2) public String isinCode; }

      ... some other @CsvRecord ....

      I also have some @FixedLengthRecord classes defined in the same package.
      If I run the following route:

      .unmarshal().bindy(BindyType.Csv, MyCamelBeans.TEST.class)

      Camel (2.10.3) fails with an NPE:

      at org.apache.camel.dataformat.bindy.BindyCsvFactory.setDefaultValuesForFields(BindyCsvFactory.java:583)
      at org.apache.camel.dataformat.bindy.BindyCsvFactory.bind(BindyCsvFactory.java:230)

      if I remove the other bindies, camel-bindy works as expected.

      Looking at the code, I've found that in BindyAbstractFactory.java :


      • method uses to initialize the model representing the classes who will
      • bind the data. This process will scan for classes according to the
      • package name provided, check the annotated classes and fields.
      • @throws Exception
        public void initModel() throws Exception
        Unknown macro: { // Find classes defined as Model if (packageNames != null) { initModelClasses(this.packageNames); } else if (type != null) { // use the package name from the type as it may refer to types in the same package String pckName = type.getPackage().getName(); initModelClasses(pckName); } else { throw new IllegalArgumentException("Either packagenames or type should be configured"); } }

      Looks like bindy scan the package even a class has been specified.

      Accordin to Claus, bindy needs to be refactored so it

      • requires the class type (no more packages)
      • uses the class type as root model
      • ... and initializes the model from the root, and follow and
        references to other classes (if the root has childs)

      This avoids picking up any other models.
      And we would know to marshal/unmarshal based on the root.




            • Assignee:
              davsclaus Claus Ibsen
              lb Luca Burgazzoli
            • Votes:
              1 Vote for this issue
              5 Start watching this issue


              • Created: