orika-mapper / orika

Simpler, better and faster Java bean mapping framework
http://orika-mapper.github.io/orika-docs/
Apache License 2.0
1.3k stars 268 forks source link

Android compatibility #272

Open TheElan opened 6 years ago

TheElan commented 6 years ago

Hi,

Couple days ago I tried to use your framework in my Android application and stumbled on problem of compability. As for android, they have their java SDK, that a bit differs from standard.

Orka uses java.beans.Introspector to do it's magic and, if I am correct, it puts dependency on whole java AWT. And the problem is, that there is no real reason to port and maintain whole AWT to android, see link. There are only few things left from java.beans, see link.

In return google proposes their implementation of most classes (except functionality that deals with AWT) from java.beans in their openbeans library , which includes Introspector.

It would be great if orika acquired android platform compatibility (there are not good alternatives for convenient mapping in Android, unfortunately).

P.S.: I guess that there is no real standard (like an interface in java library) that can describe Introspector, but still, maybe it is sensible to provide some way to swap Introspectors? For example define your own interface with default implementation from open beans or even java.beans and allow to easily swap it. That way orika will become event more independent from external libraries.

TheElan commented 6 years ago

Ok, tried to replace all java.bean dependencies for openbean (there were like 8-9 imports) and it seem to compile and pass all tests. Not tested if it deploy ok on android yet.

Can I get permissions to push my branch to your repo? (Or is there is some other way to contribute to your project? I don't really know how it is done here on github)

TheElan commented 6 years ago

This replacement may possibly solve work around that briefly saw when replaced dependencies in test classes (IntrospectorBugTestCase and SpecifiedGenericsTestCase).

TheElan commented 6 years ago

Tested deploy on android and it looks like simple replacement to openbeans solves issue with Introspector.

TheElan commented 6 years ago

Ok, now I am getting another error about class not being accessible

How to reproduce:

Originally was written in kotlin, translated to java by hand (still should compile).

Run as android instrumented test on emulator device:

@RunWith(AndroidJUnit4.class)
class CarMappingTest 
{
    @Test
    public void testCarMapping()
    {
        MapperFactory mapperFactory = DefaultMapperFactory.Builder().build();
        MapperFacade mapperFacade = mapperFactory.getMapperFacade();

        CarDto carDto = CarDto("Ford");
        Car car = mapperFacade.map(carDto, Car.class);

        Assert.assertEquals(carDto.getModel(), car.getModel());
    }    
}

public class Car
{
   String model;
   //Constructor, getters setters
}
public class CarDto
{
   String model;
   //Constructor, getters setters
}

Emulator device properties

Name: Nexus_5X_API_28
CPU/ABI: Google Play Intel Atom (x86)
Path: C:\Users\Elan-PC\.android\avd\Nexus_5X_API_28.avd
Target: google_apis_playstore [Google Play] (API level 28)
Skin: nexus_5x
SD Card: 100M
hw.dPad: no
hw.lcd.height: 1920
runtime.network.speed: full
hw.accelerometer: yes
hw.device.name: Nexus 5X
vm.heapSize: 256
skin.dynamic: yes
hw.device.manufacturer: Google
hw.lcd.width: 1080
hw.gps: yes
hw.initialOrientation: Portrait
image.androidVersion.api: 28
hw.audioInput: yes
image.sysdir.1: system-images\android-28\google_apis_playstore\x86\
tag.id: google_apis_playstore
showDeviceFrame: yes
hw.camera.back: virtualscene
hw.mainKeys: no
AvdId: Nexus_5X_API_28
hw.camera.front: emulated
hw.lcd.density: 420
avd.ini.displayname: Nexus 5X API 28
hw.arc: false
hw.gpu.mode: auto
hw.device.hash2: MD5:bc5032b2a871da511332401af3ac6bb0
hw.ramSize: 1536
hw.trackBall: no
PlayStore.enabled: true
fastboot.forceColdBoot: no
hw.battery: yes
hw.cpu.ncore: 2
hw.sdCard: yes
tag.display: Google Play
runtime.network.latency: none
hw.keyboard: yes
hw.sensors.proximity: yes
disk.dataPartition.size: 2G
hw.sensors.orientation: yes
avd.ini.encoding: UTF-8
hw.gpu.enabled: yes

Stack trace

ma.glasnost.orika.MappingException: While attempting the following mapping:
sourceType = edu.hd.elan.mom.repository.service.CarDto
destinationType = edu.hd.elan.mom.repository.service.Car
Error occurred: ma.glasnost.orika.impl.generator.CompilerStrategy$SourceCodeGenerationException: class edu.hd.elan.mom.repository.service.CarDto is not accessible
at ma.glasnost.orika.impl.generator.MapperGenerator.build(MapperGenerator.java:104)
at ma.glasnost.orika.impl.DefaultMapperFactory.buildMapper(DefaultMapperFactory.java:1478)
at ma.glasnost.orika.impl.DefaultMapperFactory.lookupMapper(DefaultMapperFactory.java:738)
at ma.glasnost.orika.impl.MapperFacadeImpl.resolveMapper(MapperFacadeImpl.java:566)
at ma.glasnost.orika.impl.MapperFacadeImpl.resolveMappingStrategy(MapperFacadeImpl.java:178)
at ma.glasnost.orika.impl.MapperFacadeImpl.map(MapperFacadeImpl.java:669)
at ma.glasnost.orika.impl.MapperFacadeImpl.map(MapperFacadeImpl.java:649)
at edu.hd.elan.mom.repository.service.EventCrudRepositoryImplTest.tmp(EventCrudRepositoryImplTest.kt:76)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at android.support.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80)
at android.support.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:61)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at android.support.test.runner.AndroidJUnit4.run(AndroidJUnit4.java:101)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:384)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2145)
Caused by: ma.glasnost.orika.impl.generator.CompilerStrategy$SourceCodeGenerationException: class edu.hd.elan.mom.repository.service.CarDto is not accessible
at ma.glasnost.orika.impl.generator.JavassistCompilerStrategy.assureTypeIsAccessible(JavassistCompilerStrategy.java:172)
at ma.glasnost.orika.impl.generator.MapperGenerator.build(MapperGenerator.java:56)
... 37 more
Caused by: javassist.NotFoundException: edu.hd.elan.mom.repository.service.CarDto
at javassist.ClassPool.get(ClassPool.java:445)
at ma.glasnost.orika.impl.generator.JavassistCompilerStrategy.assureTypeIsAccessible(JavassistCompilerStrategy.java:170)
... 38 more
TheElan commented 6 years ago

Looks like atm I won't get time to look to it closer, I will try to get back to it later.

ataraxus commented 4 years ago

any news on this?

TheElan commented 4 years ago

@ataraxus didn't try it afterwards, done all mapping by hand in that project (at least it was only few classes). Issue still may persist.

stapetro commented 4 years ago

Hello @ElanHD ,

Thanks for sharing your use case with us! I'm contributor as you. I'm a big advocate of orika-mapper. I used it before in Java EE setup and it saved a lot boilerplate code for us. I follow the issues and try to help with what I can.

I'm very far from Android development the recent years so I just follow your ideas. If you want to discuss more interactively you can also join our CHAT room.

I think the original authors haven't imagined the usage of orika with Andorid SDK. :)