Using an annotated class in BeanIO instead of an XML for mapping
Asked Answered
S

1

5

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?

Searby answered 21/12, 2014 at 20:40 Comment(0)
S
12

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

Searby answered 26/12, 2014 at 9:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.