首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法将xml转换为java.How,无法使用retrofit2将xml转换为java

无法将xml转换为java.How,无法使用retrofit2将xml转换为java
EN

Stack Overflow用户
提问于 2016-04-18 05:25:08
回答 1查看 776关注 0票数 3

嗨,我正在尝试使用rest来编写一个简单的REST客户机,我试图调用一个REST,它返回一个xml响应,但是REST不能解析xml。

改造代码

代码语言:javascript
复制
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类中没有匹配。

无法排除的反应。

代码语言:javascript
复制
<?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>
EN

回答 1

Stack Overflow用户

发布于 2016-05-16 14:18:45

在您的改造构建器中将addConverterFactory(SimpleXmlConverterFactory.create())替换为addConverterFactory(SimpleXmlConverterFactory.createNonStrict())。这将使解析器能够容忍在POJO中没有出现的xml标记。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36686008

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档