[ 
https://issues.apache.org/jira/browse/CAMEL-5958?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13861368#comment-13861368
 ] 

Luca Burgazzoli commented on CAMEL-5958:
----------------------------------------

Hi Willem,
I've removed the package support camel-wide (e.g. 
org.apache.camel.builder.DataFormatClause).

The patch's target was Camel 3.0 (or any version on which you can break API 
compatibility) but I can check if I can re-introduce the package support. One 
of the issues I see is that as today camel-bindy returns a Map<?,?> of models 
(even if a class is used as source for models) so in the current test cases: 

Map<?, ?> map = (Map<?, ?>) 
mock.getReceivedExchanges().get(0).getIn().getBody(List.class).get(0);
WeatherModel model = (WeatherModel) map.values().iterator().next();

After my patch:

WeatherModel model = 
mock.getReceivedExchanges().get(0).getIn().getBody(WeatherModel.class);

I see two options:
1) re-introduce the package support, deprecate the API and construct a Map<?,?> 
of models even if the user specify a class
2) apply the patch to a camel version on which API compatibility can be broken
 
Let me know and I'll work on it :-)



> Bindy ignores bean class type
> -----------------------------
>
>                 Key: CAMEL-5958
>                 URL: https://issues.apache.org/jira/browse/CAMEL-5958
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-bindy
>    Affects Versions: 2.10.3
>            Reporter: Luca Burgazzoli
>            Priority: Minor
>
> 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 {
>         @CsvRecord(separator=";",isOrdered=true)
>         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:
>     
> from("file:data/test?noop=true&idempotent=true&fileName=test.csv&delay=60000")
>         .split(body(String.class).tokenize("\n")).streaming()
>         .unmarshal().bindy(BindyType.Csv, MyCamelBeans.TEST.class)
>         .to("log:DS?level=INFO&showHeaders=true");
> Camel (2.10.3) fails with an NPE:
>     java.lang.NullPointerException
>             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 {
>         // 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. 



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Reply via email to