Skip to content

Add convert(Object, TypeDescriptor) method to ConversionService #25394

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

Closed
raderio opened this issue Jul 15, 2020 · 6 comments
Closed

Add convert(Object, TypeDescriptor) method to ConversionService #25394

raderio opened this issue Jul 15, 2020 · 6 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@raderio
Copy link

raderio commented Jul 15, 2020

At the moment there is the method

Object convert(@Nullable Object source, @Nullable TypeDescriptor sourceType, TypeDescriptor targetType);

And usually sourceType can be deduced from source and it is unnecessary to specify the sourceType. Please add a new convert method which will remove necessity to specify the type descriptor if it is the same as source.

Object convert(@Nullable Object source, TypeDescriptor targetType) {
    return convert(source, TypeDescriptor.forObject(source), targetType);
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 15, 2020
@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels Jul 15, 2020
@sbrannen
Copy link
Member

Does the existing <T> T convert(@Nullable Object source, Class<T> targetType) method not meet your needs in terms of convenience?

@sbrannen sbrannen added the status: waiting-for-feedback We need additional information before we can continue label Jul 15, 2020
@raderio
Copy link
Author

raderio commented Jul 15, 2020

Can you please advise how to use it when I need to convert an object to a List<T>?

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 15, 2020
@sbrannen sbrannen changed the title Add new "convert" method into ConversionService interface Add new "convert" method to ConversionService interface Jul 16, 2020
@dPechman42
Copy link

Would it be possible for me to work on this?

@sbrannen sbrannen removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 27, 2020
@sbrannen sbrannen added this to the General Backlog milestone Jul 27, 2020
@sbrannen sbrannen changed the title Add new "convert" method to ConversionService interface Add new convert(Object, TypeDescriptor) method to ConversionService Jul 27, 2020
@sbrannen sbrannen changed the title Add new convert(Object, TypeDescriptor) method to ConversionService Add convert(Object, TypeDescriptor) method to ConversionService Jul 27, 2020
@sbrannen
Copy link
Member

Can you please advise how to use it when I need to convert an object to a List<T>?

You would need a target TypeDescriptor for that.

@sbrannen sbrannen removed the status: feedback-provided Feedback has been provided label Jul 27, 2020
@sbrannen
Copy link
Member

Team Decision: assigned to the General Backlog to allow this issue to gain wider community interest.

@jhoeller
Copy link
Contributor

Since the Class-based methods can be seen as a convenience already (in comparison to the SpEL TypeConverter which just has the essential SPI methods) and since GenericConversionService has a convert(Object, TypeDescriptor) already, let's expose that method as a default method on the ConversionService interface for 6.1 now.

@jhoeller jhoeller self-assigned this Jul 14, 2023
@jhoeller jhoeller modified the milestones: General Backlog, 6.1.0-M3 Jul 14, 2023
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

5 participants