Unmarshalling随机失败,错误如下 javax.xml.bind.UnmarshalException - 链接异常: [Exception [EclipseLink-25008](Eclipse Persistence Services - 2.3.2.v20111125-r10461):org.eclipse.persistence.exceptions.XMLMarshalException 异常描述:在项目中找不到具有默认根元素DirectPaymentConfirmationRequest的描述符]
XSD
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://test.com/Ft/Pare/DirectPayment/Message/Confirmation/Request/v0.10" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified">
<xs:element name="DirectPaymentConfirmationRequest">
<!—additional child elements
</xs:element>
</xs:schema>
XML input –
<?xml version="1.0" encoding="UTF-16"?>
<DirectPaymentConfirmationRequest>
<DirectPaymentReferenceId>12345</DirectPaymentReferenceId>
<PaymentCardTransactionType>ECommerceAuthorisation</PaymentCardTransactionType>
<Amount>10</Amount>
<MerchantId>1111</MerchantId>
<AddressCheckRequested>true</AddressCheckRequested>
<AuthorisationTimeStamp>2014-02-14T13:55:50.739Z</AuthorisationTimeStamp>
<AcquirerResponse>
<ResponseCode>333</ResponseCode>
<AuthorisationCode>123456</AuthorisationCode>
<AddressCheckResult>Y</AddressCheckResult>
<CVVCheckResult>Y</CVVCheckResult>
<ProductCode>MAE</ProductCode>
<TraceId>9722461401</TraceId>
</AcquirerResponse>
<CardDetail>
<PaymentCardType>Visa</PaymentCardType>
<PanToken>232323</PanToken>
<ExpiryDate>2018</ExpiryDate>
<LastFourDigits>1234</LastFourDigits>
<BinNumber>123456</BinNumber>
<CardState>NewCard</CardState>
</CardDetail>
</DirectPaymentConfirmationRequest>
Java code
package com.transformer.generated;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"directPaymentReferenceId",
"paymentCardTransactionType",
"amount",
"merchantId",
"addressCheckRequested",
"authorisationTimeStamp",
"acquirerResponse",
"error",
"cardDetail"
} )
@XmlRootElement(name = "DirectPaymentConfirmationRequest")
public class DirectPaymentConfirmationRequest
implements Serializable{}
答案 0 :(得分:0)
引导DirectPaymentConfirmationRequest
时,您需要确保包含JAXBContext
类。如果您从Java类引导,则可以执行以下操作:
JAXBContext jc = JAXBContext.newInstance(DirectPaymentConfirmationRequest.class);
如果您生成了模型,则可以在生成的模型的包名称上创建JAXBContext
。