[ https://issues.apache.org/activemq/browse/CAMEL-398?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=48889#action_48889 ]
Claus Ibsen commented on CAMEL-398: ----------------------------------- v0.95 comments - methods in interface must also be fully javadoced BindyFactory - throws Exception is pain to work with. But I can see we have this flaw in Camels DataFormat interface - throws ClassNotFoundException should be removed as well. Nobody can recover from this one :) - why is createModel() as void? The name kinda expects it to return a Object as model or something? Find a better name if it should be void - retrieveSeparator() maybe getSeparator is a better name? - bind - consider using List<String> instead of String[] as arrays is pain to work with in Java - if parameter objects is the same in bind/unbind then the parameter should have same name, eg: models Format - T should be used a type in methods: public String format(T object) public T parse(String string) - And get rid of throws Exception. BindyCsvFactory - Program against interface. Use Map x = new HashMap instead of HashMap x = new HashMap - and your class attributes should be private and not public! - Use ObjectHelper.notEmpty for testing if a String is not empty. Use ObjectHelper.notNull to test if a mandatory parameter is not null etc. - use // for code comments inside methods and not /* */ blocks - why are you using a sortedmap in unbind? - You can use a LinkedHashMap then the order is preserved. That is the original insert order is the same order you can iterate - unbind should not use a fixed comma as separator but from the getSeparator method - getFormat would be nice to be moved into a FormatFactory so other implementation can reuse it BindyCsvDataFormat - separator should be mandatory. So you can use ObjectHelper.notEmpty() to force it be be given. Better to fail due a missing separator than to just ignore it and not unmarshal anything. - scanner close id one twice. only do it in the finally NumberPattern is still using the threadlocal stuff, please remove it > Map the content of a CSV file to a POJO using @annotation and .convertBodyTo() > ------------------------------------------------------------------------------ > > Key: CAMEL-398 > URL: https://issues.apache.org/activemq/browse/CAMEL-398 > Project: Apache Camel > Issue Type: New Feature > Components: camel-core > Affects Versions: 1.4.0 > Reporter: Charles Moulliard > Assignee: Claus Ibsen > Fix For: 2.0.0 > > Attachments: camel-bindy-v0.95.zip, camel-bindy.zip > > > Hi, > It should be nice if in a next relase of Camel, it will be possible to map > the content of a CSV file to a POJO using @annotation. > For the moment, I use an ArrayList + iterator (see code hereafter) to achieve > the extraction of the content but I'm sure that we can simplify this code > using @Annotation > and the following action (.convertBodyTo(Order<List>) by example. > Current situation > Camel route > from("file:///c:/temp/test?noop=true") > .unmarshal().csv() > .to("bean:converter?methodName=TransformMessage"); --> should be replaced by > something like .convertBodyTo(Order<List>) > Converter class > public void TransformMessage(Exchange in) { > process(in.getIn().getBody(List.class)); > } > @SuppressWarnings("unchecked") > private void process(List messages) { > > // Iterate through the list of messages > for (Iterator<ArrayList> it = messages.iterator(); > it.hasNext();) { > // Split the content of the message into field > message = it.next(); > field = (String[]) message.toArray(); > order = new Order(); > order.setId(Integer.valueOf(field[0]).intValue()); > order.setBank(field[1]); > order.setAmountFrom(Double.parseDouble(field[2])); > order.setAmountTo(Double.parseDouble(field[3])); > order.setOrderInstruction(field[4].trim()); > this.orderService.createOrder(order); > } > } > Regards, > Charles -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.