Using an annotated class in BeanIO instead of an XML for mapping

7.8k views Asked by At

I'm following this simple tutorial http://beanio.org/
Toward the end says you can use an annotated class instead of an XML file. I did that and in my factory.load() I pass the value with the name of my annotated class. and I get am org.xml.sax.SAXParseException. I believe this is caused because its expecting an XML file.

What method I need to use to pass my annotated class instead of an XML?

1

There are 1 answers

0
user29768 On BEST ANSWER

In order to use a mapping class instead of an XML you only have to add the following code

StreamFactory factory = StreamFactory.newInstance();
StreamBuilder builder = new StreamBuilder("") // Your file
    .format("delimited")
    .parser(new DelimitedParserBuilder(',')) // Sign to  use as a delimiter
    .addRecord(Yourclass.class); // class to be mapped 

factory.define(builder);

This way an XML file is not need it at all.

Source:
http://beanio.org/2.1/docs/reference/index.html#BuilderApiAndAnnotations