beanio重复没有任何子字段组件的段必须具有minOccurs = maxOccurs

时间:2017-06-05 15:25:39

标签: xml xslt jaxb

还没有使用BeanIO。我试图从CSV文件中读取一个简单的字符串列表,如下所示: AA11
BB22
CC33A
4D33L

beanio.org上最简单的例子是使用带字段的对象。我不需要那个。我想要的只是读取字符串。

我拥有什么

1。 XSLT优惠券

<beanio xmlns="http://www.beanio.org/2012/03">
    <stream name="coupons" format="csv">
        <parser>
            <property name="delimiter" value="," />
            <property name="lineSeparator" value="\n" />
            <property name="whitespaceAllowed" value="true" />
        </parser>       
        <record name="header" class="map" maxOccurs="1">            
            <field name="recordType" rid="true" literal="H" />                  
            <field name="fileDate" type="date" format="yyyy-MM-dd" />
        </record>
        <record name="detail" minOccurs="0" maxOccurs="1" class="java.lang.String" />       
    </stream>
</beanio>

2。 CouponProcessor.java

public class CouponProcessor {

    public Map<String, Boolean> readCouponCodesFromCSV(InputStream couponCsv) throws Exception {        
        StreamFactory factory = StreamFactory.newInstance();        
        factory.loadResource("/coupon_codes/coupon.xml"); // ** Problem occurs here **        
        BeanReader in = factory.createReader("coupons", new InputStreamReader(couponCsv));           

        Object record = null;
        Map<String, Boolean> couponCodeMap = new TreeMap<>();

        while ((record = in.read()) != null) {
            switch (in.getRecordName()) {
            case "header" : 
                @SuppressWarnings("unchecked")
                Map<String, Object> header = (Map<String,Object>) record;
                log.info(header.get("fileDate"));
                break;
            case "detail" :
                String code = (String) record;              
                couponCodeMap.put(code, couponCodeMap.get(code) == null ? Boolean.FALSE : Boolean.TRUE); // False='unique', True='duplicate'
            }            
        }        
        in.close();        
        return couponCodeMap;
    }
}

第3。遇到的问题

这一行

factory.loadResource("/coupon_codes/coupon.xml");


我收到以下错误:

CouponProcessor.readCouponCodesFromCSV(java.io.InputStream) throws java.lang.Exception: javax.ejb.EJBException: org.beanio.BeanIOConfigurationException: Invalid record 'detail', in stream 'coupons': Repeating segments without any child field component must have minOccurs=maxOccurs


4。问题

Q1。使用beanio可以在没有用户定义的对象的情况下映射基元/包装器和字符串吗? Q2。造成上述问题的原因是什么? Q3。如何解决这个问题?什么是最合适的解决方案?

感谢。

0 个答案:

没有答案
相关问题