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

Need more flexibility around conversion strategies and how to bootstrap different conversion strategies. [SPR-6381] #11047

Closed
spring-projects-issues opened this issue Nov 17, 2009 · 2 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 Nov 17, 2009

Oleg Zhurakousky opened SPR-6381 and commented

Related to #10464

As a developer I need:

  • Ability to create ConversionService instance with no default converters pre-registered or only have NumberToString and vice versa type converters:
    For example:
    Object.toString() is not always the right default strategy since implementation of the toString() method often tailored more toward displaying an object in the logs, rather then creating a true String representation of it
    Object to Map and vice versa, also is not always a good default strategy since Object might represent some type of a structure that could be represented as more then a single entry Map
    The bottom line is as a developer I want to have a choice and control as to how canConvert() method behaves. In other words if I want to convert Foo to String and there is no FooToString cnverter I want to see can't convert exception and not rely on the default generic strategy.

Currently in SI we have to remove bunch of converters in order to use the ConversionService

I also need ability to chain/synthesize converters. However, this strategy will not work if we have ObjectTo* and *ToObject converters since everything is an object, which means the default state of such converter must only have strongly typed converters pre-registered or empty.

Overall I think we need flexibility and therefore several strategies needed. So I think what would be appropriate is to have a Factory class with Factory methods fronting the ConversionService creation, this allowing to bootstrap several implementations.

For example

  • public static ConversionService createGenericConverter(List additionalConverters) - will retur the instance of GenericConversionService
  • public static ConversionService createDefaultConverter(List. additionalConverters) - will retur the instance of DefaultConversionService
  • public static ConversionService createSyntheticConverter(List additionalConverters) - will retur the instance of SyntheticConversionService
  • public static ConversionService createEmptySyntheticConverter()
    etc. . .

Obviously not passing any additional converters will result in the initial state of the ConversionService to correspond to the implementation of the factory method. Configuration would also be simple:
{CODE}
<bean id="conversionService" class="ConversionServiceFactory" factory-method="createSyntheticConverter">
<constructor-arg>
<list>
. . .

	</list>
</constructor-arg>

</bean>
{CODE}


Affects: 3.0 RC2

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

Oleg Zhurakousky commented

Just as another example here is the snippet of the code we currently have in SI:
{CODE}
conversionService = new DefaultConversionService();
conversionService.removeConvertible(Object.class, Map.class);
conversionService.removeConvertible(Map.class, Object.class);
conversionService.removeConvertible(Object.class, String.class);
{CODE}
I would love to only add what I need instead of remove what I don't, simply because I don't know what's there (unless I am familiar with the code) until i try.

@spring-projects-issues
Copy link
Collaborator Author

Keith Donald commented

Added ConversionServiceFactory

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0 RC3 milestone Jan 11, 2019
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