TechGeek
TechGeek

Reputation: 508

Camel bindy throwing null pointer exception when i use same positioned value multiple times

I'm using two DataFields with same positions for two different attributes. It is throwing null pointer exception.Can anyone help me how to make it work.

* CamelRoute.java*

public class ConverterRoute implements RoutesBuilder {

    private static final String SOURCE_INPUT_PATH = "file://inbox?fileName=Source.txt";

    private static final String SOURCE_OUTPUT_PATH = "file://outbox?fileName=file_$simple{date:now:yyyyMMddHHmmssSSS}.xml";

    @Override
    public void addRoutesToCamelContext(CamelContext context) throws Exception {
        context.addRoutes(new RouteBuilder() {
            public void configure() {
                try {

                    DataFormat bindyFixed = new BindyCsvDataFormat(TestOne.class);

                    XmlFriendlyNameCoder nameCoder = new XmlFriendlyNameCoder("_-", "_");
                    Dom4JDriver dom4JDriver = new Dom4JDriver(nameCoder);

                    XStreamDataFormat xStreamDataFormat = new XStreamDataFormat();
                    xStreamDataFormat.setAliases(Collections.singletonMap("TEST_ONE", TestOne.class.getCanonicalName()));
                    //xStreamDataFormat.setXstreamDriver(dom4JDriver);

                    from(SOURCE_INPUT_PATH).
                            log("Received input from file and body is ${body}").
                            split().tokenize(System.lineSeparator()).
                            unmarshal(bindyFixed).
                            marshal(xStreamDataFormat).
                            log("After Marshalling and body is ${body}").
                            to(SOURCE_OUTPUT_PATH).log("Finished Transformation").
                      end();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
}

TestOne.java

@CsvRecord(separator = "\\|", skipField = true)
public class TestOne{

    @DataField(pos = 3, required = true)
    private String testId;

    @Link
    private TestTwo testTwo;

}

TestTwo.java

@CsvRecord(separator = "\\|", skipField = true)
public class TestTwo{

    @DataField(pos = 3, required = true)
    private String mockIt;

}
java.lang.NullPointerException: null
    at org.apache.camel.dataformat.bindy.BindyCsvFactory.setDefaultValuesForFields(BindyCsvFactory.java:695) ~[camel-bindy-2.24.1.jar:2.24.1]

Added the converter route details How I'm transforming the unstructured data to xml.

Upvotes: 0

Views: 638

Answers (0)

Related Questions