Return early from composed Converter if initial conversion step returned null

See gh-23379
This commit is contained in:
Juergen Hoeller 2020-10-12 17:54:53 +02:00
parent fec89af239
commit 2a34c0ea70
1 changed files with 5 additions and 2 deletions

View File

@ -57,8 +57,11 @@ public interface Converter<S, T> {
* @since 5.3
*/
default <U> Converter<S, U> andThen(Converter<? super T, ? extends U> after) {
Assert.notNull(after, "after must not be null");
return (S s) -> after.convert(convert(s));
Assert.notNull(after, "After Converter must not be null");
return (S s) -> {
T initialResult = convert(s);
return (initialResult != null ? after.convert(initialResult) : null);
};
}
}