JAXB UnmarshalException: unexpected element (uri:"", local:"BizData")

81 Views Asked by At

I am getting the exception exception while JAXb unmarshalling the xml to jaxb convertion. I am thinking this is issue due to below line @XmlElementDecl(namespace = "urn:iso:std:iso:20022:tech:xsd:head.003.001.01", name = "BizData") public JAXBElement createBizData(BusinessDataHeaderV01 value) {

error:

jakarta.xml.bind.UnmarshalException: unexpected element (uri:"", local:"BizData"). Expected elements are <{urn:iso:std:iso:20022:tech:xsd:head.001.001.02}AppHdr>,<{urn:iso:std:iso:20022:tech:xsd:head.003.001.01}BizData>

How to resolve this issue?

Unmarshal Method

public BusinessDataHeaderV01 unmarshal(String xml) throws JAXBException, IOException {
    JAXBContext context = JAXBContext.newInstance( BusinessDataHeaderV01.class,BusinessApplicationHeaderEnvelope.class,BusinessApplicationHeaderV02.class ,iso.std.iso._20022.tech.xsd.auth_092_001.Document.class);
    Unmarshaller unmarshaller= context.createUnmarshaller();
    return  (BusinessDataHeaderV01) unmarshaller
            .unmarshal(new StringReader(sampleFile));
  }

Object factory class

**
 * This object contains factory methods for each 
 * Java content interface and Java element interface 
 * generated in the iso.std.iso._20022.tech.xsd.head_003_001 package. 
 * <p>An ObjectFactory allows you to programatically 
 * construct new instances of the Java representation 
 * for XML content. The Java representation of XML 
 * content can consist of schema derived interfaces 
 * and classes representing the binding of schema 
 * type definitions, element declarations and model 
 * groups.  Factory methods for each of these are 
 * provided in this class.
 * 
 */
@XmlRegistry
public class ObjectFactory {

    private final static QName _BizData_QNAME = new QName("urn:iso:std:iso:20022:tech:xsd:head.003.001.01", "BizData");

    /**
     * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: iso.std.iso._20022.tech.xsd.head_003_001
     * 
     */
    public ObjectFactory() {
    }

    /**
     * Create an instance of {@link BusinessDataHeaderV01 }
     * 
     */
    public BusinessDataHeaderV01 createBusinessDataHeaderV01() {
        return new BusinessDataHeaderV01();
    }

    /**
     * Create an instance of {@link BusinessApplicationHeaderEnvelope }
     * 
     */
    public BusinessApplicationHeaderEnvelope createBusinessApplicationHeaderEnvelope() {
        return new BusinessApplicationHeaderEnvelope();
    }

    /**
     * Create an instance of {@link StrictPayload }
     * 
     */
    public StrictPayload createStrictPayload() {
        return new StrictPayload();
    }

    /**
     * Create an instance of {@link JAXBElement }{@code <}{@link BusinessDataHeaderV01 }{@code >}
     * 
     * @param value
     *     Java instance representing xml element's value.
     * @return
     *     the new instance of {@link JAXBElement }{@code <}{@link BusinessDataHeaderV01 }{@code >}
     */
    @XmlElementDecl(namespace = "urn:iso:std:iso:20022:tech:xsd:head.003.001.01", name = "BizData")
    public JAXBElement<BusinessDataHeaderV01> createBizData(BusinessDataHeaderV01 value) {
        return new JAXBElement<BusinessDataHeaderV01>(_BizData_QNAME, BusinessDataHeaderV01 .class, null, value);
    }

}

Sample xml:

<BizData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:head.003.001.01 head.003.001.02_DTCC.xsd">
    <Hdr>
        <AppHdr xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:head.001.001.02 head.001.001.02.xsd">
            <Fr>
                <OrgId>
                    <Id>
                        <OrgId>
                            <Othr>
                                <Id>xxxx</Id>
                            </Othr>
                        </OrgId>
                    </Id>
                </OrgId>
            </Fr>
            <To>
                <OrgId>
                    <Id>
                        <OrgId>
                            <Othr>
                                <Id>xxxx</Id>
                            </Othr>
                        </OrgId>
                    </Id>
                </OrgId>
            </To>
            <BizMsgIdr>xxxxxxxxxxxxx</BizMsgIdr>
            <MsgDefIdr>xxxxxxxx</MsgDefIdr>
            <CreDt>2023-08-01T09:40:39Z</CreDt>
        </AppHdr>
    </Hdr>
    <Pyld>
        <Document
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:auth.092.001.03 auth.092.001.03_ESMAUG_DATREJ_1.0.0.xsd"
            xmlns="urn:iso:std:iso:20022:tech:xsd:auth.092.001.03">
            <DerivsTradRjctnSttstclRpt>
                <RjctnSttstcs>
                    <Rpt>
                        <RefDt>2023-08-01Z</RefDt>
                        <TtlNbOfRpts>1</TtlNbOfRpts>
                        <TtlNbOfRptsAccptd>1</TtlNbOfRptsAccptd>
                        <TtlNbOfRptsRjctd>0</TtlNbOfRptsRjctd>
                        <TtlNbOfTxs>0</TtlNbOfTxs>
                        <TtlNbOfTxsAccptd>
                            <All>0</All>
                            <New>0</New>
                            <Mod>0</Mod>
                        </TtlNbOfTxsAccptd>
                        <TtlNbOfTxsRjctd>
                            <All>0</All>
                            <New>0</New>
                            <Mod>0</Mod>
                        </TtlNbOfTxsRjctd>
                        <RjctnSttstcs>
                            <CtrPtyId>
                                <RptgCtrPty>
                                    <LEI>549300FM54TXULUKO729</LEI>
                                </RptgCtrPty>
                                <RptSubmitgNtty>
                                    <LEI>549300FM54TXULUKO729</LEI>
                                </RptSubmitgNtty>
                                <NttyRspnsblForRpt>
                                    <LEI>549300FM54TXULUKO729</LEI>
                                </NttyRspnsblForRpt>
                            </CtrPtyId>
                            <RptSttstcs>
                                <TtlNbOfRpts>1</TtlNbOfRpts>
                                <TtlNbOfRptsAccptd>0</TtlNbOfRptsAccptd>
                                <TtlNbOfRptsRjctd>0</TtlNbOfRptsRjctd>
                            </RptSttstcs>
                            <DerivSttstcs>
                                <DtldSttstcs>
                                    <TtlNbOfTxs>0</TtlNbOfTxs>
                                    <TtlNbOfTxsAccptd>
                                        <All>0</All>
                                        <New>0</New>
                                        <Mod>0</Mod>
                                    </TtlNbOfTxsAccptd>
                                    <TtlNbOfTxsRjctd>
                                        <All>0</All>
                                        <New>0</New>
                                        <Mod>0</Mod>
                                    </TtlNbOfTxsRjctd>
                                    <TxsRjctnsRsn>
                                        <TxId>
                                            <ActnTp>NEWT</ActnTp>
                                            <RptgTmStmp>2023-08-01T01:34:47Z</RptgTmStmp>
                                            <DerivEvtTmStmp>
                                                <Dt>2023-08-01</Dt>
                                            </DerivEvtTmStmp>
                                            <OthrCtrPty>
                                                <Lgl>
                                                    <Id>
                                                        <LEI>549300FM54TXULUKO729</LEI>
                                                    </Id>
                                                </Lgl>
                                            </OthrCtrPty>
                                            <UnqIdr>
                                                <UnqTxIdr>TESTUTITESTUTITEST12TESTUTITESTUTITESTTESTUTITESTUTI</UnqTxIdr>
                                            </UnqIdr>
                                        </TxId>
                                        <Sts>ACPT</Sts>
                                    </TxsRjctnsRsn>
                                </DtldSttstcs>
                            </DerivSttstcs>
                        </RjctnSttstcs>
                        <RjctnSttstcs>
                            <CtrPtyId>
                                <RptgCtrPty>
                                    <LEI>549300FM54TXULUKO729</LEI>
                                </RptgCtrPty>
                                <RptSubmitgNtty>
                                    <LEI>549300FM54TXULUKO729</LEI>
                                </RptSubmitgNtty>
                                <NttyRspnsblForRpt>
                                    <LEI>549300FM54TXULUKO729</LEI>
                                </NttyRspnsblForRpt>
                            </CtrPtyId>
                            <RptSttstcs>
                                <TtlNbOfRpts>1</TtlNbOfRpts>
                                <TtlNbOfRptsAccptd>0</TtlNbOfRptsAccptd>
                                <TtlNbOfRptsRjctd>0</TtlNbOfRptsRjctd>
                            </RptSttstcs>
                            <DerivSttstcs>
                                <DtldSttstcs>
                                    <TtlNbOfTxs>0</TtlNbOfTxs>
                                    <TtlNbOfTxsAccptd>
                                        <All>0</All>
                                        <New>0</New>
                                        <Mod>0</Mod>
                                    </TtlNbOfTxsAccptd>
                                    <TtlNbOfTxsRjctd>
                                        <All>0</All>
                                        <New>0</New>
                                        <Mod>0</Mod>
                                    </TtlNbOfTxsRjctd>
                                    <TxsRjctnsRsn>
                                        <TxId>
                                            <ActnTp>MODI</ActnTp>
                                            <RptgTmStmp>2023-08-01T01:34:47Z</RptgTmStmp>
                                            <DerivEvtTmStmp>
                                                <Dt>2023-08-01</Dt>
                                            </DerivEvtTmStmp>
                                            <OthrCtrPty>
                                                <Lgl>
                                                    <Id>
                                                        <LEI>549300FM54TXULUKO729</LEI>
                                                    </Id>
                                                </Lgl>
                                            </OthrCtrPty>
                                            <UnqIdr>
                                                <UnqTxIdr>TESTUTITESTUTITEST12TESTUTITESTUTITESTTESTUTITESTUTI</UnqTxIdr>
                                            </UnqIdr>
                                        </TxId>
                                        <Sts>ACPT</Sts>
                                    </TxsRjctnsRsn>
                                </DtldSttstcs>
                            </DerivSttstcs>
                        </RjctnSttstcs>
                    </Rpt>
                </RjctnSttstcs>
            </DerivsTradRjctnSttstclRpt>
        </Document>
    </Pyld>
</BizData>
0

There are 0 best solutions below