1
1
/*
2
- * Copyright 2002-2022 the original author or authors.
2
+ * Copyright 2002-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
31
31
32
32
import org .springframework .core .DecoratingProxy ;
33
33
import org .springframework .core .ResolvableType ;
34
- import org .springframework .core .convert .ConversionException ;
35
34
import org .springframework .core .convert .ConversionFailedException ;
36
35
import org .springframework .core .convert .ConversionService ;
37
36
import org .springframework .core .convert .ConverterNotFoundException ;
@@ -140,11 +139,7 @@ public boolean canConvert(@Nullable Class<?> sourceType, Class<?> targetType) {
140
139
@ Override
141
140
public boolean canConvert (@ Nullable TypeDescriptor sourceType , TypeDescriptor targetType ) {
142
141
Assert .notNull (targetType , "Target type to convert to cannot be null" );
143
- if (sourceType == null ) {
144
- return true ;
145
- }
146
- GenericConverter converter = getConverter (sourceType , targetType );
147
- return (converter != null );
142
+ return (sourceType == null || getConverter (sourceType , targetType ) != null );
148
143
}
149
144
150
145
/**
@@ -160,15 +155,11 @@ public boolean canConvert(@Nullable TypeDescriptor sourceType, TypeDescriptor ta
160
155
*/
161
156
public boolean canBypassConvert (@ Nullable TypeDescriptor sourceType , TypeDescriptor targetType ) {
162
157
Assert .notNull (targetType , "Target type to convert to cannot be null" );
163
- if (sourceType == null ) {
164
- return true ;
165
- }
166
- GenericConverter converter = getConverter (sourceType , targetType );
167
- return (converter == NO_OP_CONVERTER );
158
+ return (sourceType == null || getConverter (sourceType , targetType ) == NO_OP_CONVERTER );
168
159
}
169
160
170
- @ Override
171
161
@ SuppressWarnings ("unchecked" )
162
+ @ Override
172
163
@ Nullable
173
164
public <T > T convert (@ Nullable Object source , Class <T > targetType ) {
174
165
Assert .notNull (targetType , "Target type to convert to cannot be null" );
@@ -195,24 +186,6 @@ public Object convert(@Nullable Object source, @Nullable TypeDescriptor sourceTy
195
186
return handleConverterNotFound (source , sourceType , targetType );
196
187
}
197
188
198
- /**
199
- * Convenience operation for converting a source object to the specified targetType,
200
- * where the target type is a descriptor that provides additional conversion context.
201
- * Simply delegates to {@link #convert(Object, TypeDescriptor, TypeDescriptor)} and
202
- * encapsulates the construction of the source type descriptor using
203
- * {@link TypeDescriptor#forObject(Object)}.
204
- * @param source the source object
205
- * @param targetType the target type
206
- * @return the converted value
207
- * @throws ConversionException if a conversion exception occurred
208
- * @throws IllegalArgumentException if targetType is {@code null},
209
- * or sourceType is {@code null} but source is not {@code null}
210
- */
211
- @ Nullable
212
- public Object convert (@ Nullable Object source , TypeDescriptor targetType ) {
213
- return convert (source , TypeDescriptor .forObject (source ), targetType );
214
- }
215
-
216
189
@ Override
217
190
public String toString () {
218
191
return this .converters .toString ();
0 commit comments