Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Construct org.springframework.core.convert.TypeDescriptor programatically for collections [SPR-7597] #12253

Closed
spring-projects-issues opened this issue Sep 27, 2010 · 4 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Sep 27, 2010

!!Use pwebb rather than philw opened SPR-7597 and commented

Although TypeDescriptor can determine collection element types from fields and methods as far as I can there is no way to do this programmatically. Could adding a TypeDescriptor.forCollection method be considered?


Affects: 3.0.4

Attachments:

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

!!Use pwebb rather than philw commented

Patch

@spring-projects-issues
Copy link
Collaborator Author

Keith Donald commented

Phil,
Can you see if the existing TypeDescriptor#forObject(Object) meets your needs?

@spring-projects-issues
Copy link
Collaborator Author

!!Use pwebb rather than philw commented

Keith,

The problem with forObject is that it can only deduce the generic collection type if there is an element in the collection, same with valueOf. If you build the TypeDescription from a field or methodParameter then the generic type can be deduced but what I really want to do is build a TypeDescriptor programatically when I know the element type that should be in the collection. This would be particularly useful when writing test cases for converters that deal with collections.

Another idea that had for this (and this might be a bit crazy) is to use the converter service to populate Lists based on the generic type of the list. So for example I convert from MyEnum.class to List<MyEnum> by having a converter that calls MyEnum.values().

This code probably explains better than my ramblings:

https://github.com/philwebb/springfaces/blob/master/springfaces/src/main/java/org/springframework/springfaces/converter/ClassToEnumsConverter.java

https://github.com/philwebb/springfaces/blob/master/springfaces/src/test/java/org/springframework/springfaces/converter/ClassToEnumsConverterTest.java

Phil.

@spring-projects-issues
Copy link
Collaborator Author

Keith Donald commented

Added TypeDescriptor.collection and TypeDescriptor.map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant