简体   繁体   English

在BeanIO中使用带注释的类而不是XML进行映射

[英]Using an annotated class in BeanIO instead of an XML for mapping

I'm following this simple tutorial http://beanio.org/ 我正在关注这个简单的教程http://beanio.org/
Toward the end says you can use an annotated class instead of an XML file. 最后说,您可以使用带注释的类而不是XML文件。 I did that and in my factory.load() I pass the value with the name of my annotated class. 我这样做并在我的factory.load()传递了带有注释类名称的值。 and I get am org.xml.sax.SAXParseException . 我得到的是org.xml.sax.SAXParseException I believe this is caused because its expecting an XML file. 我相信这是因为它期待一个XML文件。

What method I need to use to pass my annotated class instead of an XML? 我需要使用什么方法来传递带注释的类而不是XML?

In order to use a mapping class instead of an XML you only have to add the following code 要使用映射类而不是XML,您只需添加以下代码

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. 这样,XML文件根本不需要它。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM