mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
452f1b877c
Prior to this commit, ObjectToObjectConverter considered the return type of non-static `to[targetType.simpleName]()` methods but did not consider the return type of static `valueOf(sourceType)`, `of(sourceType)`, and `from(sourceType)` methods. This led to scenarios in which `canConvert()` returned `true`, but a subsequent `convert()` invocation resulted in a ConverterNotFoundException, which violates the contract of the converter. This commit addresses this issue by taking into account the return type of a static valueOf/of/from factory method when determining if the ObjectToObjectConverter supports a particular conversion. Whereas the existing check in `determineToMethod()` ensures that the method return type is assignable to the `targetType`, the new check in `determineFactoryMethod()` leniently ensures that the method return type and `targetType` are "related" (i.e., reside in the same type hierarchy). Closes gh-28609