Skip to content

Multiple Converters from same source type to different Collection types not properly supported [SPR-11369] #15995

@spring-projects-issues

Description

@spring-projects-issues

Brandon Zeeb opened SPR-11369 and commented

The GenericConversionService has a private static class ConverterCacheKey which is used to map source and target TypeDescriptors to a GenericConverter. This class is used to aggregate the hashCodes of two TypeDescriptors (source and target).

The current TypeDescriptor hashCode only looks at the bare Java Class<?>, which is fine for primitives and none collection types. In the case of Collections types with generics, only using the bare Java type of the Collection makes it impossible to register two Converters with the same target collection type.
ie:

  1. Converter<String, Set<String>>
  2. Converter<String, Set<Integer>>

The field resolvableType contains information on both the Collection type and it's generic types. Perhaps this field should be used instead?

I have rated this priority initially as "Critical" given it is not possible to register Converters with the same Collection type that differ on generic types, which is a blocker in our applications. We need this to work, and would prefer not to only accept Collection<String>.


No further details from SPR-11369

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions