Не удалось найти класс «com.fasterxml.jackson.databind.ext.CoreXMLDeserializers» для обработки значений типа » javax.xml.bind.JAXBElement в Android

#java #android #xml #jackson

Вопрос:

Я использую библиотеку Джексона, чтобы попытаться десериализовать XML в своем приложении для Android.

Градуировка, включающая Джексона, выглядит следующим образом:

 // Normal Jackson libraries
    compile 'com.fasterxml.jackson.core:jackson-core:2.12.3'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.12.3'
    compile "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.12.3"
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.3'
    implementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-scala_2.11', version: '2.12.3'
    implementation 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.12.3'
 

Конфигурация XmlMapper для десериализации выглядит следующим образом:

 XmlMapper objectMapper = new XmlMapper();
                        objectMapper.registerModule(new JodaModule());
                        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
                        objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
                        objectMapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
                        objectMapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
                        objectMapper.disable(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES);
                        objectMapper.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
                        objectMapper.disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES);
                        objectMapper.disable(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES);
                        objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);

                        ClinicalDocument res = objectMapper.readValue(s, ClinicalDocument.class);
 

Но в последней строке выше я получил следующую ошибку:

 java.lang.IllegalStateException: Failed to find class `com.fasterxml.jackson.databind.ext.CoreXMLDeserializers` for handling values of type `javax.xml.bind.JAXBElement<QTY>`, problem: (java.lang.ExceptionInInitializerError) null
        at com.fasterxml.jackson.databind.ext.OptionalHandlerFactory.instantiate(OptionalHandlerFactory.java:237)
        at com.fasterxml.jackson.databind.ext.OptionalHandlerFactory.findDeserializer(OptionalHandlerFactory.java:196)
        at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findOptionalStdDeserializer(BasicDeserializerFactory.java:1821)
        at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findDefaultDeserializer(BasicDeserializerFactory.java:2120)
        at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.findStdDeserializer(BeanDeserializerFactory.java:182)
        at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:130)
        at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:414)
        at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:349)
        at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:264)
        at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
        at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
        at com.fasterxml.jackson.databind.DeserializationContext.findContextualValueDeserializer(DeserializationContext.java:558)
        at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.createContextual(CollectionDeserializer.java:188)
        at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.createContextual(CollectionDeserializer.java:28)
        at com.fasterxml.jackson.databind.DeserializationContext.handlePrimaryContextualization(DeserializationContext.java:765)
        at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:550)
        at com.fasterxml.jackson.databind.deser.std.DelegatingDeserializer.resolve(DelegatingDeserializer.java:59)
        at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:293)
        at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
        at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
        at com.fasterxml.jackson.databind.DeserializationContext.findNonContextualValueDeserializer(DeserializationContext.java:581)
        at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:539)
        at com.fasterxml.jackson.databind.deser.std.DelegatingDeserializer.resolve(DelegatingDeserializer.java:59)
        at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:293)
        at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
        at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
        at com.fasterxml.jackson.databind.DeserializationContext.findContextualValueDeserializer(DeserializationContext.java:558)
        at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.createContextual(CollectionDeserializer.java:188)
        at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.createContextual(CollectionDeserializer.java:28)
        at com.fasterxml.jackson.databind.DeserializationContext.handlePrimaryContextualization(DeserializationContext.java:765)
        at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:550)
        at com.fasterxml.jackson.databind.deser.std.DelegatingDeserializer.resolve(DelegatingDeserializer.java:59)
        at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:293
 

где класс кол-во это:

 import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlType;


@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "QTY")
@XmlSeeAlso({
    RTOMOPQ.class,
    RTOPQPQ.class,
    RTOQTYQTY.class,
    REAL.class,
    INT.class,
    PQ.class,
    MO.class,
    TS.class
})
public abstract class QTY extends ANY {

}
 

and the ANY class that QTY extends is:

 @XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ANY")
@XmlSeeAlso({
    BL.class,
    ANYNonNull.class,
    CR.class,
    SLISTTS.class,
    GLISTPQ.class,
    SLISTPQ.class,
    GLISTTS.class,
    QTY.class,
    II.class,
    CD.class,
    URL.class,
    BIN.class
})
public abstract class ANY {

    @XmlAttribute(name = "nullFlavor")
    protected List<String> nullFlavor;

  
    public List<String> getNullFlavor() {
        if (nullFlavor == null) {
            nullFlavor = new ArrayList<String>();
        }
        return this.nullFlavor;
    }
}
 

Do you know how to solve this problem? I’m loosing hours without any success.

Thank you very much in advance!