Skip to content

Numerous updates to conversion service #132

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
wants to merge 6 commits into from

Conversation

philwebb
Copy link
Member

Changes are primarily to support conversion of enums with interfaces and to allow performance optimization when converting byte arrays.

See individual commits for details

Issues: SPR-9566, SPR-9692, SPR-9927, SPR-9928

Refactor internal workings of GenericConversionService in order to
better support future enhancements.  This commit should not affect
existing behavior.

Issue: SPR-9927
Introduce new ConditionalConversion interface that can be applied to
Converter, ConverterFactory or GenericConverter interfaces to make
them conditional.  Prior to this commit the only
ConditionalGenericConverter could be conditional.

Issue: SPR-9928
Prior to this commit conversion between like types would often result
in a copy of the object.  This can be problematic in the case of large
byte arrays and objects that do not have a default constructor.

The ConversionService SPI now includes canBypassConvert methods that
can be used to deduce when conversion is not needed.  Several existing
converters have been updated to ensure they only apply when source and
target types differ.

This change introduces new methods to the ConversionService that will
break existing implementations.  However, it anticipated that most
users are consuming the ConversionService interface rather then
extending it.

Issue: SPR-9566
@philwebb
Copy link
Member Author

@cbeams This commit has now been reworked following the review comments in:
philwebb#1

Specifically:

  • The use of ExpectedException causes NoSuchMethodErrors for me under both Eclipse and Gradle. Presumably you're getting different results? Please run tests like TypeDescriptorTests to confirm, and let's figure out how to make everything work.

I have removed ExpectedException for now, we can return to this later

  • TypeDescriptor has been made final - why? What do you think the likelihood is of this being a breaking change for people, i.e. how likely is it that folks might have extended this type?

TypeDescriptor is no longer final

This is mainly due to the fact that both issues touch the same areas of code so create atomic pull requests is hard. This pull request still deals with a number of issues but now the commits are much more logically organized. I have tried to order them in terms of how controversial they are so that you can work from the bottom up

  • both SPR-9566 and SPR-9692 have their fixVersion set for both 3.1.3 and 3.2 RC1. Given the scope of these changes, I am hesitant to backport them to 3.1.3 (still need to understand the complete impact even to 3.2). Do you have a strong case for backporting one or both?

Neither should be backported IMHO. I have removed 3.1.3 from the fixVersion field

  • It appears that these changes modify the conversion algorithm to match superclasses with a higher precedence than interfaces. As per your comments in SPR-9692, this would seem to introduce a backward-compatibility problem. Do you have a rationale as to why this change is merited, i.e. that the previous behavior is simply wrong, that it is very unlikely to actually affect anyone, etc.?

I spoke to @jhoeller about why the search changed from 3.0 to 3.1, he recalled that there was a good reason but not exactly what it was. The new algorithm does not fundamentally change the way that the type hierarchy is searched, it just considers java. and javax. packages after other packages (see the updated commit message).

Thanks for the review, it was very helpful!

EnumToStringConverter in now conditional and only matches Enums that
do not implement interfaces that can be converted.

Issue: SPR-9692
@philwebb
Copy link
Member Author

@cbeams I have updated the request again becuase I thought of a better way to fix the enum issue that does not involve changing the class search order. See commit 9272f48. The new implementation simply makes EnumToStringConverter conditional on the fact that no interfaces can be converted.

@cbeams
Copy link
Contributor

cbeams commented Oct 30, 2012

Thanks, Phil, this is now merged into SpringSource/master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants