2016-04-18 19 views
2

こんにちは私は単純なレストクライアントを書くためにretrofitを使用しようとしていますが、私はREST API GETを呼び出して、 XMLを解析できません。 org.simpleframework.xml.core.ElementException:要素 'featureSetID' がクラスで試合を持っていないスレッド "メイン" java.lang.RuntimeExceptionでRetrofitはxmlをjava.Howに変換できませんretrofit2を使用してxmlをJavaに変換する

レトロフィットコード

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()); 

例外

で com.intuit.schema.platform.webs.catalog.internal.offers.v3.Offer $ retrofit2.converter.simplexml.SimpleXmlResponseBodyConverter.convert(SimpleXmlResponseBodyConverter.java:44)における第1ライン で製品

アンマーシャリングできない応答。

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

答えて

-1

あなたの改造ビルダーでaddConverterFactory()SimpleXmlConverterFactory.createNonStrict()addConverterFactoryと(()SimpleXmlConverterFactory.create)を交換してください。これにより、パーサーはあなたのPOJOにはないxmlタグに寛容になります

+0

これは質問への答えを提供しません。十分な[評判](http://stackoverflow.com/help/whats-reputation)があれば、[任意の投稿にコメントする]ことができます(http://stackoverflow.com/help/privileges/comment)。代わりに、[質問者からの明確化を必要としない回答を提供する](http://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-c​​an- i-do-代わりに)。 – Raju

+0

投稿のすぐ下の[編集](http://stackoverflow.com/posts/37256147/edit)リンクをクリックして投稿を改善しようとします。コメントはコード書式設定機能をサポートしていません。 – Raju

関連する問題