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

ConversionService cannot convert from Object to String anymore by default [SPR-11693] #16315

Closed
spring-projects-issues opened this issue Apr 14, 2014 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression)

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Apr 14, 2014

Oliver Drotbohm opened SPR-11693 and commented

On Spring 3.2.8 a default ConversionService instance (e.g. DefaultFormattingConversionService will answer the following call with true:

conversionService.canConvert(Object.class, String.class);

As of Spring 4.0.1 the same call returns false which is due to that change (introduced for #15884). From the commit however, it's not quite clear why the implementation of ObjectToObjectConverter now explicitly excludes String.valueOf(…).


Affects: 4.0.1, 4.0.2, 4.0.3

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Apr 17, 2014

Juergen Hoeller commented

While that change did come as part of #15884 where a general "toX()" convention was baked into ObjectToObjectConverter, it is intentional in that we never meant to return true for the generic Object-to-String case. Instead, our FallbackObjectToStringConverter always had specific rules when it would say true here, such as a specifically declared constructor or valueOf method that can perform specific String conversion here. However, due to the generic "String.valueOf(Object)" method, that convention unfortunately made it return true for the super-generic Object-to-String case... and that basically got corrected as part of #15884.

In fact, if a caller wants to accept any toString() result, he shouldn't call the ConversionService in the first place but rather simply call toString() himself.

Juergen

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)
Projects
None yet
Development

No branches or pull requests

2 participants