Skip to content

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

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions