Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 574
user29768 Avatar asked Dec 20 '22 08:12

user29768


1 Answers

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

like image 123
user29768 Avatar answered May 08 '23 03:05

user29768