404-not-find / orika

Automatically exported from code.google.com/p/orika
2 stars 0 forks source link

Issue with type matching #157

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. I registered a custom mapper for <Collection, Collection> i.e. any 
collection to another collection
2. It works fine in my simple test cases where I provide a subclass of  
java.util.Collection from java.util but when I use with Hibernate (which 
represents List as a PersistentBag),  I see the following issue
   a. A field of type Collection<SomeType> is represented by Hibernate as a PersistentBag
   b. Hibernate does not have any "generics" definition on PersistentBag
 Now when Orika looks for a registered mapper in
     DefaultMapperFactory.getRegisteredMapper(Type<A> typeA, Type<B> typeB, boolean includeAutoGeneratedMappers)

It is not able to find my custom mapper. On debugging I found that 
Type.isAssignableFrom(Type<?> other) has a check for actualTypeArguments.size

            if (this.getActualTypeArguments().length != other.getActualTypeArguments().length) {
                return false;
            }

Here "this" is Collection<Object> and "other" is PersistentBag (which 
implements List and Collection)
Theoretically, I would expect my custom mapper to be chosen for any 2 
collection pairs. So I guess the code in Type.isAssignableFrom() should 
consider non-existent generic type to be of type Object

What version of the product are you using? On what operating system?
4.1.5 on Mac OS X

Please provide any additional information below.

jdk 6

Original issue reported on code.google.com by mohankri...@gmail.com on 16 Apr 2014 at 6:44

GoogleCodeExporter commented 8 years ago
Attached modified Type.java with changes to the isAssignableFrom method that 
fixes the issue. 

Original comment by mohankri...@gmail.com on 16 Apr 2014 at 5:27

Attachments:

GoogleCodeExporter commented 8 years ago
The fix is attached to the issue. I am using the fix by specifying the fix 
class in the classpath. Would like to know if and when this fix can be made 
available in Orika itself

Original comment by mohankri...@gmail.com on 25 Nov 2014 at 5:19