Android + Dozer throws IllegalArgumentException

731 views Asked by At

I am trying to use Dozer in an Android project. But when I try to map a Bean to another Bean, it throws the following error :

06-16 09:45:56.687    1727-1727/ch.heia_fr.tic.ipal.test_dozer E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: ch.heia_fr.tic.ipal.test_dozer, PID: 1727
    java.lang.RuntimeException: Unable to start activity ComponentInfo{ch.heia_fr.tic.ipal.test_dozer/ch.heia_fr.tic.ipal.test_dozer.MainActivity}: java.lang.IllegalArgumentException: http://apache.org/xml/features/validation/schema
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2760)
            at android.app.ActivityThread.access$900(ActivityThread.java:177)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5944)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
     Caused by: java.lang.IllegalArgumentException: http://apache.org/xml/features/validation/schema
            at org.apache.harmony.xml.parsers.DocumentBuilderFactoryImpl.setAttribute(DocumentBuilderFactoryImpl.java:86)
            at org.dozer.loader.xml.XMLParserFactory.createDocumentBuilderFactory(XMLParserFactory.java:56)
            at org.dozer.loader.xml.XMLParserFactory.createParser(XMLParserFactory.java:35)
            at org.dozer.loader.xml.MappingStreamReader.<init>(MappingStreamReader.java:43)
            at org.dozer.loader.xml.MappingFileReader.<init>(MappingFileReader.java:44)
            at org.dozer.DozerBeanMapper.loadFromFiles(DozerBeanMapper.java:219)
            at org.dozer.DozerBeanMapper.loadCustomMappings(DozerBeanMapper.java:209)
            at org.dozer.DozerBeanMapper.initMappings(DozerBeanMapper.java:315)
            at org.dozer.DozerBeanMapper.getMappingProcessor(DozerBeanMapper.java:192)
            at org.dozer.DozerBeanMapper.map(DozerBeanMapper.java:120)
            at ch.heia_fr.tic.ipal.test_dozer.MainActivity.onCreate(MainActivity.java:26)
            at android.app.Activity.performCreate(Activity.java:6289)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2760)
            at android.app.ActivityThread.access$900(ActivityThread.java:177)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5944)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)

Here is my build.gradle :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "ch.heia_fr.tic.ipal.test_dozer"
        minSdkVersion 19
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions{
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'net.sf.dozer:dozer:5.4.0'
}

And the code that poses problem :

PersonBean bean = new PersonBean();
bean.setFirstName("Bob");
bean.setLastName("Robert");
bean.setStreet("Main Street");
bean.setTown("Bern");

Mapper mapper = new DozerBeanMapper();
PersonDTO dto = mapper.map(bean, PersonDTO.class

I think the problem comes from the missing XML MappingFile but I don't know where to put it in an android project.

Thanks

1

There are 1 answers

0
txuslee On

It doesn't even start to search for the mapping file. If you look into the DocumentBuilderFactory implemented in the android-sdk-22 you'll see that the method is not implemented. It actually throws an exception.

I guess that xml bean mapping definition is not supported in android. Try with API mapping as it appears in the documentation.

EDIT: It doesn't look to be working either. Dozer still tries to load both mappings (builder mappings and file based mappings) at map invocation. So long, I've tried Dozer, Orika and ModelMapper, but only the last one works in android.