Using annotated class in BeanIO instead of XML for mapping
I am following this simple tutorial http://beanio.org/
By the end says you can use annotated class instead of XML file. I did this and in mine factory.load()
passed a value with the name of my annotated class. and I get am org.xml.sax.SAXParseException
. I believe this is because it is expecting an XML file.
What method should I use to pass my annotated class instead of XML?
+3
source to share
1 answer
To use a mapping class instead of XML, you need 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);
Thus, the XML file is not needed at all.
Source:
http://beanio.org/2.1/docs/reference/index.html#BuilderApiAndAnnotations
+8
source to share