Mapping List on Xml File

瀏覽次數:121 次
跳到第一則未讀訊息

Kobe Roosens

未讀,
2019年3月5日 清晨7:10:402019/3/5
收件者:beanio-users
Dear BeanIo users, 

I have a request for assistance on this file.
For some reason the list segment is not properly interpreted as a list
Based on the reference guide, this should be encoded like in the code samples below, however in that case I get an errormessage as noted below.

If I change the collection tag to the following, then the xml file is correctly translated to a bean, but only one ePrestation is read.
<segment name="ePrestationList" class="be.cm.apps.application.beanz.ePrestation" collection="list" minOccurs="1" maxOccurs="unbounded">
    <segment name="ePrestation" >

Any ideas what I could have done wrong?
Or alternative solutions to properly translate this xml into a bean?


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




Definition file:
<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>

Sample xml to be processed:
<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>

Involved classes:
public class RequestEattest {

private RequestContext requestContext;
private Eattest eattest;

public RequestContext getRequestContext() {
return requestContext;
}
public void setRequestContext(RequestContext requestContext) {
this.requestContext = requestContext;
}

public Eattest getEattest() {
return eattest;
}
public void setEattest(Eattest eattest) {
this.eattest = eattest;
}
}

package be.cm.apps.application.beanz;

public class RequestContext {
private String b2bReference;
private String externalReference;
private String creationDate;
private String creationTime;
private String requestorNihii;
private String messageDate;
private String messageTime;
private String receptionDate;
private String receptionTime;
private String requestorType;
private String nippinReference;

public String getReceptionDate() {
return receptionDate;
}
public void setReceptionDate(String receptionDate) {
this.receptionDate = receptionDate;
}
public String getReceptionTime() {
return receptionTime;
}
public void setReceptionTime(String receptionTime) {
this.receptionTime = receptionTime;
}
public String getB2bReference() {
return b2bReference;
}
public void setB2bReference(String b2bReference) {
this.b2bReference = b2bReference;
}
public String getExternalReference() {
return externalReference;
}
public void setExternalReference(String externalReference) {
this.externalReference = externalReference;
}
public String getCreationDate() {
return creationDate;
}
public void setCreationDate(String creationDate) {
this.creationDate = creationDate;
}
public String getCreationTime() {
return creationTime;
}
public void setCreationTime(String creationTime) {
this.creationTime = creationTime;
}
public String getRequestorNihii() {
return requestorNihii;
}
public void setRequestorNihii(String requestorNihii) {
this.requestorNihii = requestorNihii;
}
public String getMessageDate() {
return messageDate;
}
public void setMessageDate(String messageDate) {
this.messageDate = messageDate;
}
public String getMessageTime() {
return messageTime;
}
public void setMessageTime(String messageTime) {
this.messageTime = messageTime;
}
public String getRequestorType() {
return requestorType;
}
public void setRequestorType(String requestorType) {
this.requestorType = requestorType;
}
public String getNippinReference() {
return nippinReference;
}
public void setNippinReference(String nippinReference) {
this.nippinReference = nippinReference;
}
}

public class Eattest {
private String invoicingDate;
private String invoicingTime;
private String attestorNihii;
private String providerFeeAmount;
private String entrepriseNumber;
private String receivedNissNumber;
private List<ePrestation> ePrestationList = new ArrayList<>();

public List<ePrestation> getePrestationList() {
return ePrestationList;
}
public void setePrestationList(List<ePrestation> ePrestationList) {
this.ePrestationList = ePrestationList;
}
public String getInvoicingDate() {
return invoicingDate;
}
public void setInvoicingDate(String invoicingDate) {
this.invoicingDate = invoicingDate;
}
public String getInvoicingTime() {
return invoicingTime;
}
public void setInvoicingTime(String invoicingTime) {
this.invoicingTime = invoicingTime;
}
public String getAttestorNihii() {
return attestorNihii;
}
public void setAttestorNihii(String attestorNihii) {
this.attestorNihii = attestorNihii;
}
public String getProviderFeeAmount() {
return providerFeeAmount;
}
public void setProviderFeeAmount(String providerFeeAmount) {
this.providerFeeAmount = providerFeeAmount;
}
public String getEntrepriseNumber() {
return entrepriseNumber;
}
public void setEntrepriseNumber(String entrepriseNumber) {
this.entrepriseNumber = entrepriseNumber;
}
public String getReceivedNissNumber() {
return receivedNissNumber;
}
public void setReceivedNissNumber(String receivedNissNumber) {
this.receivedNissNumber = receivedNissNumber;
}
}

public class ePrestation {
private int order;
private String creationDetailDate;
private String creationDetailTime;
private String providerNihii;
private String prestationCode;
private int quantity;
private String beginDate;
private String endDate;
public int getOrder() {
return order;
}

public void setOrder(int order) {
this.order = order;
}
public String getCreationDetailDate() {
return creationDetailDate;
}
public void setCreationDetailDate(String creationDetailDate) {
this.creationDetailDate = creationDetailDate;
}
public String getCreationDetailTime() {
return creationDetailTime;
}
public void setCreationDetailTime(String creationDetailTime) {
this.creationDetailTime = creationDetailTime;
}
public String getProviderNihii() {
return providerNihii;
}
public void setProviderNihii(String providerNihii) {
this.providerNihii = providerNihii;
}
public String getPrestationCode() {
return prestationCode;
}
public void setPrestationCode(String prestationCode) {
this.prestationCode = prestationCode;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public String getBeginDate() {
return beginDate;
}
public void setBeginDate(String beginDate) {
this.beginDate = beginDate;
}
public String getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
}



Jimmy Godin

未讀,
2019年3月5日 上午11:51:402019/3/5
收件者:bea...@googlegroups.com
You should put collection="list" on the ePrestationList segment. Drop the ePrestation segment and only keep the fields

Op di 5 mrt. 2019 13:10 schreef Kobe Roosens <kobe.r...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "beanio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beanio+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kobe Roosens

未讀,
2019年3月6日 凌晨3:10:202019/3/6
收件者:beanio-users
Like this?

               
<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>

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

This setup is mostly to read incoming xml's and thus I prefer not to remove the ePrestation tag.
That said, I have tried it and it results in the following error:

Exception in thread "main" org.beanio.InvalidRecordException: Invalid 'registerEattestRequest' record
 ==> Invalid 'beginDate':  Expected minimum 1 occurrences
 ==> Invalid 'creationDetailDate':  Expected minimum 1 occurrences
 ==> Invalid 'quantity':  Expected minimum 1 occurrences
 ==> Invalid 'endDate':  Expected minimum 1 occurrences
 ==> Invalid 'creationDetailTime':  Expected minimum 1 occurrences
 ==> Invalid 'prestationCode':  Expected minimum 1 occurrences
 ==> Invalid 'order':  Expected minimum 1 occurrences
 ==> Invalid 'providerNihii':  Expected minimum 1 occurrences
at org.beanio.internal.parser.UnmarshallingContext.validate(UnmarshallingContext.java:200)
at org.beanio.internal.parser.BeanReaderImpl.internalRead(BeanReaderImpl.java:111)
at org.beanio.internal.parser.BeanReaderImpl.read(BeanReaderImpl.java:67)
at be.cm.apps.application.beanz.ExampleReader.readRequestBean2(ExampleReader.java:74)
at be.cm.apps.application.Main.main(Main.java:29)

Which corresponds from what I understood from the reference guide: every tag should be mentioned in the definition file, even if it's not required in the bean.
So I've removed the corresponding ePrestation tag from the xml file, and now it only reads the first occurence of the ePrestation and disregards the next occurence.

I really don't understand this, my setup is pretty much identical to the reference guide, so why doesn't this work?


Op dinsdag 5 maart 2019 17:51:40 UTC+1 schreef Jimmy G:

Kobe Roosens

未讀,
2019年3月6日 凌晨3:16:372019/3/6
收件者:beanio-users
Ok, topic can be closed.
It seems to have something to do with finding the correct getter/setter methods.
After manually defining the getter/setter methods, the entire list of ePrestations is now properly loading into a list.

Thanks!

(in case you want to see the correct definition:)

                   
<segment name="ePrestation" class="be.cm.apps.application.beanz.EPrestation" collection="list" minOccurs="1" maxOccurs="unbounded" getter="getePrestationList" setter="setePrestationList">

                       
<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>
public class Eattest {
   
private String invoicingDate;
   
private String invoicingTime;
   
private String attestorNihii;
   
private String providerFeeAmount;
   
private String entrepriseNumber;
   
private String receivedNissNumber;

   
private List<EPrestation> ePrestationList = new ArrayList<>();

   
public List<EPrestation> getePrestationList() {    return ePrestationList;    }
   
public void setePrestationList(List<EPrestation> ePrestationList) {    this.ePrestationList = ePrestationList;    }

   
public String getInvoicingDate() {
     
return invoicingDate;
   
}
   
public void setInvoicingDate(String invoicingDate) {
     
this.invoicingDate = invoicingDate;
   
}
   
public String getInvoicingTime() {
     
return invoicingTime;
   
}
   
public void setInvoicingTime(String invoicingTime) {
     
this.invoicingTime = invoicingTime;
   
}
   
public String getAttestorNihii() {
     
return attestorNihii;
   
}
   
public void setAttestorNihii(String attestorNihii) {
     
this.attestorNihii = attestorNihii;
   
}
   
public String getProviderFeeAmount() {
     
return providerFeeAmount;
   
}
   
public void setProviderFeeAmount(String providerFeeAmount) {
     
this.providerFeeAmount = providerFeeAmount;
   
}
   
public String getEntrepriseNumber() {
     
return entrepriseNumber;
   
}
   
public void setEntrepriseNumber(String entrepriseNumber) {
     
this.entrepriseNumber = entrepriseNumber;
   
}
   
public String getReceivedNissNumber() {
     
return receivedNissNumber;
   
}
   
public void setReceivedNissNumber(String receivedNissNumber) {
     
this.receivedNissNumber = receivedNissNumber;
   
}
}




Op dinsdag 5 maart 2019 13:10:40 UTC+1 schreef Kobe Roosens:
回覆所有人
回覆作者
轉寄
0 則新訊息