BeanIO的Xml映射,列表未正确解释

时间:2019-03-05 12:20:59

标签: java xml bean-io

我需要有关此BeanIO Xml映射的帮助。 由于某种原因,列表段未正确解释为列表 根据参考指南,应该像下面的代码示例中那样对它进行编码,但是在这种情况下,我会收到如下所述的错误消息。

如果将collection标记更改为以下标记,则xml文件将正确转换为Bean,但是仅读取一个ePrestation。 (这也与参考指南相冲突)     

任何想法我可能做错了什么? 还是将这个xml正确转换为bean的替代解决方案?

curl -X POST \
  https://atc.mywebpage.net/jira/rest/api/2/search \
  -H 'Content-Type: application/json' \
  -H 'Postman-Token: xxxxxxxxxxxxxxxxxxxxxxx' \
  -H 'cache-control: no-cache' \
  -d '{
    "jql": "component = LOLO AND fixVersion = '\''18/3 Patch-2'\''",
    "startAt": 0,
    "maxResults": 300,
    "fields": [
        "issuetype",
        "created",
        "status",
        "summary",
        "customfield_10002",
        "customfield_10003",
        "customfield_11201",
        "customfield_10006"
    ]
}'

定义文件:

Exception in thread "main" org.beanio.BeanIOConfigurationException: Invalid segment 'ePrestation', in segment 'ePrestationList', in segment 'eattest', in record 'registerEattestRequest', in stream 'requestStream': No such property 'ePrestation' in class 'be.cm.apps.application.beanz.Eattest'
        at org.beanio.internal.compiler.ProcessorSupport.process(ProcessorSupport.java:93)
        at org.beanio.internal.compiler.ParserFactorySupport.createStream(ParserFactorySupport.java:95)
        at org.beanio.internal.compiler.xml.XmlParserFactory.createStream(XmlParserFactory.java:51)
        at org.beanio.internal.compiler.StreamCompiler.createStreamDefinitions(StreamCompiler.java:149)
        at org.beanio.internal.compiler.StreamCompiler.loadMapping(StreamCompiler.java:103)
        at org.beanio.internal.DefaultStreamFactory.load(DefaultStreamFactory.java:58)
        at org.beanio.StreamFactory.loadResource(StreamFactory.java:215)
        at org.beanio.StreamFactory.loadResource(StreamFactory.java:198)
        at be.cm.apps.application.beanz.ExampleReader.readRequestBean2(ExampleReader.java:62)
        at be.cm.apps.application.Main.main(Main.java:29)
Caused by: org.beanio.BeanIOConfigurationException: No such property 'ePrestation' in class 'be.cm.apps.application.beanz.Eattest'
        at org.beanio.internal.compiler.ParserFactorySupport.getPropertyDescriptor(ParserFactorySupport.java:1331)
        at org.beanio.internal.compiler.ParserFactorySupport.reflectCollectionType(ParserFactorySupport.java:1143)
        at org.beanio.internal.compiler.ParserFactorySupport.reflectAggregationType(ParserFactorySupport.java:988)
        at org.beanio.internal.compiler.ParserFactorySupport.finalizeSegmentIteration(ParserFactorySupport.java:709)
        at org.beanio.internal.compiler.ParserFactorySupport.finalizeSegment(ParserFactorySupport.java:697)
        at org.beanio.internal.compiler.ProcessorSupport.handleComponent(ProcessorSupport.java:135)
        at org.beanio.internal.compiler.ProcessorSupport.handleComponent(ProcessorSupport.java:133)
        at org.beanio.internal.compiler.ProcessorSupport.handleComponent(ProcessorSupport.java:133)
        at org.beanio.internal.compiler.ProcessorSupport.handleComponent(ProcessorSupport.java:125)
        at org.beanio.internal.compiler.ProcessorSupport.handleComponent(ProcessorSupport.java:109)
        at org.beanio.internal.compiler.ProcessorSupport.process(ProcessorSupport.java:46)
        ... 9 more

Process finished with exit code 1

要处理的XML示例:

<beanio xmlns="http://www.beanio.org/2012/03"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.beanio.org/2012/03 http://www.beanio.org/2012/03/mapping.xsd">

    <stream name="requestStream" format="xml" xmlType="none"  >
        <record name="registerEattestRequest" class="be.cm.apps.application.beanz.RequestEattest" minOccurs="1" maxOccurs="1">
            <segment name="requestContext" minOccurs="1" maxOccurs="1"  class="be.cm.apps.application.beanz.RequestContext" >
                <field name="b2bReference"  />
                <field name="externalReference"  />
                <field name="creationDate"  />
                <field name="creationTime"  />
                <field name="requestorNihii"  />
                <field name="messageDate"  />
                <field name="messageTime"  />
                <field name="receptionDate" />
                <field name="receptionTime" />
                <field name="requestorType"  />
                <field name="nippinReference" />
            </segment>
            <segment name="eattest" minOccurs="1" maxOccurs="1" class="be.cm.apps.application.beanz.Eattest" >
                <field name="invoicingDate" />
                <field name="invoicingTime" />
                <field name="attestorNihii" />
                <field name="providerFeeAmount" />
                <field name="entrepriseNumber" />
                <field name="receivedNissNumber" />
                <segment name="ePrestationList"   >
                    <segment name="ePrestation" class="be.cm.apps.application.beanz.ePrestation" collection="list" minOccurs="1" maxOccurs="unbounded">
                        <field name="order" />
                        <field name="creationDetailDate" />
                        <field name="creationDetailTime" />
                        <field name="providerNihii" />
                        <field name="prestationCode" />
                        <field name="quantity" />
                        <field name="beginDate" />
                        <field name="endDate" />
                    </segment>

                </segment>
            </segment>
        </record>
    </stream>
</beanio>

涉及的课程:

<registerEattestRequest>
    <requestContext>
        <b2bReference>MULTI_KO2019030510:12:41</b2bReference>
        <externalReference>10765515001.MULTI_KO20190305</externalReference>
        <creationDate>2019-03-05</creationDate>
        <creationTime>10:12:41</creationTime>
        <requestorNihii>10765515001</requestorNihii>
        <messageDate>2019-03-05</messageDate>
        <messageTime>10:12:41</messageTime>
        <receptionDate>2019-03-05</receptionDate>
        <receptionTime>10:12:41</receptionTime>
        <requestorType>persphysician</requestorType>
        <nippinReference>MULTI_KO2019030510:12:41</nippinReference>
    </requestContext>
    <eattest>
        <invoicingDate>2019-03-05</invoicingDate>
        <invoicingTime>10:12:41</invoicingTime>
        <attestorNihii>10765515001</attestorNihii>
        <providerFeeAmount>24.00</providerFeeAmount>
        <entrepriseNumber>0635769870</entrepriseNumber>
        <receivedNissNumber>19640721 489 80</receivedNissNumber>
        <ePrestationList>
            <ePrestation>
                <order>2</order>
                <creationDetailDate>2019-03-05</creationDetailDate>
                <creationDetailTime>10:12:41</creationDetailTime>
                <providerNihii>10765515001</providerNihii>
                <prestationCode>101010</prestationCode>
                <quantity>1</quantity>
                <beginDate>2019-03-05</beginDate>
                <endDate>2019-03-05</endDate>
            </ePrestation>
            <ePrestation>
                <order>3</order>
                <creationDetailDate>2019-03-05</creationDetailDate>
                <creationDetailTime>10:12:41</creationDetailTime>
                <providerNihii>10765515001</providerNihii>
                <prestationCode>144034</prestationCode>
                <quantity>1</quantity>
                <beginDate>2019-03-05</beginDate>
                <endDate>2019-03-05</endDate>
            </ePrestation>
        </ePrestationList>
    </eattest>
</registerEattestRequest>

1 个答案:

答案 0 :(得分:1)

通过参考4.5.2. Repeating Segments部分,应该没有用于在定义XML中重复嵌套元素的嵌套段标签。同时,输入XML中的嵌套标签<ePrestationList><ePrestation>应该随之改变。按照以下代码片段更新XML应该可以解决问题。

定义XML

            ...
            <field name="receivedNissNumber" />
            <!-- <segment name="ePrestationList"> -->
            <segment name="ePrestationList"
                class="be.cm.apps.application.beanz.ePrestation" collection="list"
                minOccurs="1" maxOccurs="unbounded">
                <field name="order" />
                <field name="creationDetailDate" />
                <field name="creationDetailTime" />
                <field name="providerNihii" />
                <field name="prestationCode" />
                <field name="quantity" />
                <field name="beginDate" />
                <field name="endDate" />
            </segment>
            <!-- </segment> -->
        </segment>  

输入XML

    ...
    <ePrestationList>
        <!-- <ePrestation> -->
        <order>2</order>
        <creationDetailDate>2019-03-05</creationDetailDate>
        <creationDetailTime>10:12:41</creationDetailTime>
        <providerNihii>10765515001</providerNihii>
        <prestationCode>101010</prestationCode>
        <quantity>1</quantity>
        <beginDate>2019-03-05</beginDate>
        <endDate>2019-03-05</endDate>
        <!-- </ePrestation> --> 
    </ePrestationList>
    <!-- <ePrestation> -->
    <ePrestationList>
        <order>3</order>
        <creationDetailDate>2019-03-05</creationDetailDate>
        <creationDetailTime>10:12:41</creationDetailTime>
        <providerNihii>10765515001</providerNihii>
        <prestationCode>144034</prestationCode>
        <quantity>1</quantity>
        <beginDate>2019-03-05</beginDate>
        <endDate>2019-03-05</endDate>
    <!-- </ePrestation> -->
    </ePrestationList>
</eattest>