gavioto / cloning

Automatically exported from code.google.com/p/cloning
Other
0 stars 0 forks source link

Android Support #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
cloning, any version
Android, any version

Cloning requires objenesis which requires sun.reflect.ReflectionFactory in 
order to instantiate without a constructor.

While objenesis plans to support Android, the ticket has been sitting 
'accepted' since 2010 and no release of objenesis has been made since then!  
The direct workaround is mentioned here:

http://stackoverflow.com/questions/3121515/is-it-possible-to-bypass-constructors
-when-instantiating-objects-in-android

Looks simple enough, no?  Detect a running Android VM and change the 
newInstance() implementation.  I may fork and give it a try.

Original issue reported on code.google.com by cherry...@gmail.com on 4 Jul 2012 at 7:53

GoogleCodeExporter commented 9 years ago
added IInstantiationStrategy that allows construction of new instances. Also 
added a cloner constructor that allows providing of an IInstantiationStrategy.

Original comment by kostas.k...@googlemail.com on 17 Jul 2012 at 7:36

GoogleCodeExporter commented 9 years ago
It turns out that there are two different strategies that you need to implement 
based on the android OS version.  The ObjectInputStream method will only work 
on older android OS versions.  Did you test on newer versions?  They require a 
similar method based on ObjectStreamClass

Original comment by cherry...@gmail.com on 17 Jul 2012 at 9:28

GoogleCodeExporter commented 9 years ago
Hi Cherrydev, I didn't create any strategy for Android OS, I don't have a way 
to test it anyway.

The IInstantiationStrategy is impl in 1.8.2 and when this is deployed you could 
use it to implement any strategy you require for your android app. In fact, if 
it works well for you, you might want to share it and become part of cloner 
library ;)

Original comment by kostas.k...@googlemail.com on 17 Jul 2012 at 9:30

GoogleCodeExporter commented 9 years ago
1.8.2 is out (but not sure if sync'd with maven central yet)

Original comment by kostas.k...@googlemail.com on 25 Jul 2012 at 9:23

GoogleCodeExporter commented 9 years ago
So... Does that mean that cloner is now only optionally dependant on Objenesis? 
 The approach I had taken previously is to implement my own Objenesis and pass 
that to the Cloner.

Original comment by cherry...@gmail.com on 25 Jul 2012 at 11:26

GoogleCodeExporter commented 9 years ago
not sure what will happen if your remove objenesis from classpath. It might not 
work because still some dependent classes import objenesis.

But now you can implement your own instantiation strategy and pass it to 
Cloner's constructor:

public Cloner(IInstantiationStrategy instantiationStrategy)

The instantiation strategy has one method only:

public interface IInstantiationStrategy
{
    <T> T newInstance(final Class<T> c);
}

Original comment by kostas.k...@googlemail.com on 29 Jul 2012 at 5:35

GoogleCodeExporter commented 9 years ago
Hello !

I need Cloning to run on Gingerbread / Android API 10 and upwards. Could you 
please share the strategies to make Cloning work ? with or without Objenesis ?

Best Regards

H.D. Le

Original comment by lhdang...@gmail.com on 21 Apr 2013 at 11:15