#81 Resolve collection hints from generic type information

closed
None
5
2007-03-26
2007-03-09
No

Hi, it would be a great feature if dozer could read collection hints from generics. (I know, you need Java 5 for that ;)

Especially I do NOT want to define following XML...

<mapping>
<class-a>example.UserGroup</class-a>
<class-b>example.UserGroupPrime</class-b>
<field>
<a>users</a>
<b>users</b>
<a-hint>example.User</a-hint>
<b-hint>example.UserPrime</b-hint>
</field>
</mapping>

... if dozer could resolve those hints from the beans I have already parameterized, e.g.:

public class UserGroupPrime {
public void setUsers(List<UserPrime> aUsers) {
users = aUsers;
}
...
}

I think the size of many XML config files would decrease enormously :)

(I attached a simple example test case.)

Discussion

  • Franz Garsombke

    Franz Garsombke - 2007-03-09

    Logged In: YES
    user_id=550744
    Originator: NO

    Very cool idea. Let me discuss this with Matt.

    Franz

     
  • Franz Garsombke

    Franz Garsombke - 2007-03-10

    Logged In: YES
    user_id=550744
    Originator: NO

    I will try to get this into the next release. Maybe a week or two out...

     
  • Franz Garsombke

    Franz Garsombke - 2007-03-10
    • assigned_to: nobody --> fgarsombke
     
  • Franz Garsombke

    Franz Garsombke - 2007-03-19

    Logged In: YES
    user_id=550744
    Originator: NO

    Not as easy as I first thought...found this Generics comparison. It looks like it is difficult (impossible) to get the Type information at runtime...Anyone have thoughts on this? --

    This is from the article I found on generics...

    Issue number two, and I think this is probably an even bigger issue, is that because J""ava's generics implementation relies on erasure of the type parameter, when you get to runtime, you don't actually have a faithful representation of what you had at compile time. When you apply reflection to a generic List in Java, you can't tell what the List is a List of. It's just a List. Because you've lost the type information, any type of dynamic code-generation scenario, or reflection-based scenario, simply doesn't work. If there's one trend that's pretty clear to me, it's that there's more and more of that. And it just doesn't work, because you've lost the type information. Whereas in our implementation, all of that information is available. You can use reflection to get the System.Type for object List<T>. You cannot actually create an instance of it yet, because you don't know what T is. But then you can use reflection to get the System.Type for int. You can then ask reflection to please put these two together and create a List<int>, and you get another System.Type for List<int>. So representationally, anything you can do at compile time you can also do at runtime.

    http://www.artima.com/intv/generics2.html

     
  • Christoph Göldner

    Logged In: YES
    user_id=1717313
    Originator: YES

    I don't know if you have seen the attached test case. There I read the generic type information from the setter method at runtime with following code:

    Method setter = UserGroupPrime.class.getMethod("setUsers", List.class);
    Type[] parameterTypes = setter.getGenericParameterTypes();
    assertEquals(1, parameterTypes.length);
    ParameterizedType parameterType = (ParameterizedType) parameterTypes[0];
    assertEquals(List.class, parameterType.getRawType());
    assertEquals(UserPrime.class, parameterType.getActualTypeArguments()[0]);

    I think that is a simple example how it basically works. Hope you get it into next dozer release :)

     
  • Franz Garsombke

    Franz Garsombke - 2007-03-19

    Logged In: YES
    user_id=550744
    Originator: NO

    Ok...this should help. I couldn't find the right method calls...this looks correct.

    Thanks,

    Franz

     
  • Franz Garsombke

    Franz Garsombke - 2007-03-19

    Logged In: YES
    user_id=550744
    Originator: NO

    Ok...this should help. I couldn't find the right method calls...this looks correct.

    Thanks,

    Franz

     
  • Franz Garsombke

    Franz Garsombke - 2007-03-20

    Logged In: YES
    user_id=550744
    Originator: NO

    Your unit tests now pass. This will be in the next release. You can get the latest code out of svn if you want to preview.

    Franz

     
  • Franz Garsombke

    Franz Garsombke - 2007-03-20
    • status: open --> pending
     
  • Christoph Göldner

    • status: pending --> open
     
  • Christoph Göldner

    Logged In: YES
    user_id=1717313
    Originator: YES

    Hey, that sounds good! I will try it.

    Many thanks!

     
  • Franz Garsombke

    Franz Garsombke - 2007-03-22
    • status: open --> pending
     
  • Franz Garsombke

    Franz Garsombke - 2007-03-26
    • status: pending --> closed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks