嗨,我正在尝试使用rest来编写一个简单的REST客户机,我试图调用一个REST,它返回一个xml响应,但是REST不能解析xml。
改造代码
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(API_URL)
.addConverterFactory(SimpleXmlConverterFactory.create())
.build();
// Create an instance of our OfferClient API interface.
OfferClient offerClient = retrofit.create(OfferClient.class);
// Create a call instance for looking up offers.
String offerID="20000798";
Call<Offer> call = offerClient.offers(offerID);
Offer offer = call.execute().body();
System.out.println("Offer Response..."+ offer.getDescription());线程"main“中的异常: org.simpleframework.xml.core.ElementException:元素'featureSetID‘在retrofit2.converter.simplexml.SimpleXmlResponseBodyConverter.convert(SimpleXmlResponseBodyConverter.java:44)的第1行的com.intuit.schema.platform.webs.catalog.internal.offers.v3.Offer$Product类中没有匹配。
无法排除的反应。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<offer xmlns="http://schema.intuit.com/platform/webs/catalog/internal/offers/v3">
<offerID>20000798</offerID>
<name>QBOA + QBO Plus + QBOP Enhanced CA CAD for Accountants</name>
<description>QBOA + QBO Plus + QBOP Enhanced CA CAD for Accountants</description>
<effectiveStartDate>2015-12-13T00:00:00-0800</effectiveStartDate>
<currency>CAD</currency>
<region>CA</region>
<country>CA</country>
<offerType>Free</offerType>
<offerLevel>BASE</offerLevel>
<customerSegment>ACCOUNTANT</customerSegment>
<extendedCustomerSegment>REGULAR</extendedCustomerSegment>
<salesChannel>DIRECT</salesChannel>
<isListPriceOffer>true</isListPriceOffer>
<product>
<productID>22000220</productID>
<packageId>21001070</packageId>
<code>QBOA</code>
<name>QuickBooks Online Accountant</name>
<description>QuickBooks Online Accountant</description>
<grantOfferingType>Intuit.smallbusiness.qba.web</grantOfferingType>
<billingServiceType>/service/intuit/qboa</billingServiceType>
<featureSet>
<featureSetID>25001595</featureSetID>
<code>QBOA_STANDARD</code>
<name>QBO Accountant Standard</name>
<status>Active</status>
<description>QuickBooks Online Accountant Standard</description>
<feature>
<code>STANDARD</code>
<name>Standard</name>
<type>Feature Set</type>
</feature>
</featureSet>
<charge>
<chargeID>23001499</chargeID>
<name>QuickBooks Online Accountant Standard</name>
<description>QuickBooks Online Accountant Standard CA CAD Monthly Free</description>
<type>Recurring</type>
</charge>
</product>
<product>
<productID>22000000</productID>
<packageId>21001071</packageId>
<code>QBO</code>
<name>QuickBooks Online</name>
<description>QuickBooks Online</description>
<grantOfferingType>Intuit.sbe.salsa.default</grantOfferingType>
<billingServiceType>/service/intuit/qbo</billingServiceType>
<featureSet>
<featureSetID>25000000</featureSetID>
<code>QBO_PLUS</code>
<name>QBO_PLUS</name>
<status>Active</status>
<description>QuickBooks Online Plus</description>
<feature>
<code>PLUS</code>
<name>Plus</name>
<type>Feature Set</type>
</feature>
</featureSet>
<charge>
<chargeID>23001500</chargeID>
<name>QuickBooks Online Plus</name>
<description>QuickBooks Online Plus Accountant CA CAD Monthly Free</description>
<type>Recurring</type>
</charge>
</product>
<product>
<productID>22000154</productID>
<dependentOnProductId>22000000</dependentOnProductId>
<dependentOnProductCode>QBO</dependentOnProductCode>
<packageId>21001323</packageId>
<code>QBOP</code>
<name>QuickBooks Online Payroll</name>
<description>QuickBooks Online Payroll</description>
<grantOfferingType>Intuit.ems.iop</grantOfferingType>
<billingServiceType>/service/intuit/qbo/qbop</billingServiceType>
<featureSet>
<featureSetID>25000537</featureSetID>
<code>ENHANCED</code>
<name>ENHANCED</name>
<status>Active</status>
<description>ENHANCED</description>
<feature>
<code>ENHANCED</code>
<name>Enhanced</name>
<type>Feature Set</type>
</feature>
</featureSet>
<charge>
<chargeID>23001868</chargeID>
<name>QuickBooks Online Payroll Enhanced</name>
<description>QuickBooks Online Payroll Enhanced CA CAD Monthly Free</description>
<type>Recurring</type>
</charge>
<charge>
<chargeID>23001964</chargeID>
<name>QuickBooks Online Payroll Enhanced Usage</name>
<description>QuickBooks Online Payroll Enhanced Accountant CA CAD Usage Free</description>
<type>Usage</type>
</charge>
</product>
<transition>
<transitionType>Resubscribe</transitionType>
<fromOfferID>20000798</fromOfferID>
<toOfferID>20000798</toOfferID>
</transition>
</offer>发布于 2016-05-16 14:18:45
在您的改造构建器中将addConverterFactory(SimpleXmlConverterFactory.create())替换为addConverterFactory(SimpleXmlConverterFactory.createNonStrict())。这将使解析器能够容忍在POJO中没有出现的xml标记。
https://stackoverflow.com/questions/36686008
复制相似问题