android jackson xml,java – 在android上使用jackson-dataformat-xml

我正在使用android上的jackson-dataformat-xml

我有一些非常基本的代码,可以在oracle jre上正常工作

JacksonXmlModule module = new JacksonXmlModule();

module.setDefaultUseWrapper(false);

XmlMapper xmlMapper = new XmlMapper(module);

首先我尝试official documentation改编为gradle(由我,不确定是否正确完成):

compile 'com.fasterxml.jackson.core:jackson-core:2.5.4'

compile 'com.fasterxml.jackson.core:jackson-annotations:2.5.4'

compile 'com.fasterxml.jackson.core:jackson-databind:2.5.4'

compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.5.4'

compile 'org.codehaus.woodstox:woodstox-core-asl:4.4.1'

compile 'javax.xml.stream:stax-api:1.0-2'

结果:gradle将关于将corelibraries捆绑到应用程序中的构建时间失败

...

:app:preDexDebug

trouble processing "javax/xml/stream/EventFilter.class":

Ill-advised or mistaken usage of a core class (java.* or javax.*)

when not building a core library.

...

试图追随肖恩answer的第二次尝试

(基本上他用前缀名称重新打包corelib并重建jackson-dataformat-xml以使用前缀名称)

compile 'com.fasterxml.jackson.core:jackson-core:2.1.2'

compile 'com.fasterxml.jackson.core:jackson-annotations:2.1.2'

compile 'com.fasterxml.jackson.core:jackson-databind:2.1.2'

// Repackaged XML-specific libraries

compile 'edu.usf.cutr.android.xml:jackson-dataformat-xml-android:2.1.2'

compile 'edu.usf.cutr.android.xml:stax2-api-android:3.1.1'

compile 'edu.usf.cutr.android.xml:stax-api-android:1.0-2'

compile 'edu.usf.cutr.android.xml:aalto-xml-android:0.9.8'

复制时构建时间失败

Duplicate files copied in APK META-INF/services/com.fasterxml.jackson.core.ObjectCodec

添加:

packagingOptions {

...

exclude 'META-INF/services/com.fasterxml.jackson.core.JsonFactory'

exclude 'META-INF/services/com.fasterxml.jackson.core.ObjectCodec'

}

当添加它构建和部署的排除项时,但是在下面的stackdump上运行时失败(AFAIK它找不到SAX提供程序,即使它被添加到我的理解的类路径中)

edu.usf.cutr.javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.MXParserFactory not found

at edu.usf.cutr.javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:72)

at edu.usf.cutr.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:176)

at edu.usf.cutr.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:92)

at edu.usf.cutr.javax.xml.stream.XMLInputFactory.newInstance(XMLInputFactory.java:136)

at com.fasterxml.jackson.dataformat.xml.XmlFactory.(XmlFactory.java:97)

at com.fasterxml.jackson.dataformat.xml.XmlFactory.(XmlFactory.java:85)

at com.fasterxml.jackson.dataformat.xml.XmlFactory.(XmlFactory.java:82)

at com.fasterxml.jackson.dataformat.xml.XmlMapper.(XmlMapper.java:46)

在#1或#2上前进的正确方法是什么?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值